欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

返回suggester的类型(Returning the type of the suggester)

程序员文章站 2022-06-26 11:58:20
...

Returning the type of the suggester

  有时你需要知道确切的suggester类型,以解析其结果。 typed_keys参数可用于在响应中更改suggester的名称,它将以其类型为前缀。

  考虑以下两个suggester term 和phrase的例子:

POST _search?typed_keys
{
  "suggest": {
    "text" : "some test mssage",
    "my-first-suggester" : {
      "term" : {
        "field" : "message"
      }
    },
    "my-second-suggester" : {
      "phrase" : {
        "field" : "message"
      }
    }
  }
}

  在回应中,suggester命名将分别改为term#my-first-suggester和phrase#my-second-suggester,以反映每个suggestion的类型:

{
  "suggest": {
    "term#my-first-suggester": [ 【1】
      {
        "text": "some",
        "offset": 0,
        "length": 4,
        "options": []
      },
      {
        "text": "test",
        "offset": 5,
        "length": 4,
        "options": []
      },
      {
        "text": "mssage",
        "offset": 10,
        "length": 6,
        "options": [
          {
            "text": "message",
            "score": 0.8333333,
            "freq": 4
          }
        ]
      }
    ],
    "phrase#my-second-suggester": [ 【2】
      {
        "text": "some test mssage",
        "offset": 0,
        "length": 16,
        "options": [
          {
            "text": "some test message",
            "score": 0.030227963
          }
        ]
      }
    ]
  },
  ...
}

  【1】名字my-first-suggester现在包含term前缀。 

  【2】名字my-second-suggester现在包含phrase前缀。

 

 

原文地址:https://www.elastic.co/guide/en/elasticsearch/reference/5.4/returning-suggesters-type.html