2

我想写一个查询来分析一个或多个字段?

即当前的分析器需要文本才能运行,而不是传递文本我想传递一个字段值。

如果我有这样的文件

{
    "desc": "A document description",
    "name": "This name is not original",
    "amount": 3000
}

我想返回类似下面的东西

{
    "desc": ["document", "description"],
    "name": ["name", "original"],
    "amount": 3000
}
4

1 回答 1

3

您可以使用Term Vectors 或 Multi Term Vectors来实现您正在寻找的内容:

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-termvectors.html

您必须指定所需字段的ID以及字段,它将为您拥有的每个文档以及您可以轻松禁用的某些其他信息返回一组已分析的标记。

GET /exampleindex/_doc/_mtermvectors
{
  "ids": [
    "1","2"
  ],
  "parameters": {
    "fields": [
      "*"
    ]
  }
}

将返回以下内容:

"docs": [
    {
      "_index": "exampleindex",
      "_type": "_doc",
      "_id": "1",
      "_version": 2,
      "found": true,
      "took": 0,
      "term_vectors": {
        "desc": {
          "field_statistics": {
            "sum_doc_freq": 5,
            "doc_count": 2,
            "sum_ttf": 5
          },
          "terms": {
            "amazing": {
              "term_freq": 1,
              "tokens": [
                {
                  "position": 1,
                  "start_offset": 3,
                  "end_offset": 10
                }
              ]
            },
            "an": {
              "term_freq": 1,
              "tokens": [
                {
                  "position": 0,
                  "start_offset": 0,
                  "end_offset": 2
                }
              ]
            }
于 2018-04-27T09:44:53.697 回答