Elasticsearch未突出显示所有匹配项

问题描述 投票:0回答:1

我很难理解为什么以下查询对象不能使ES突出显示_source列中的所有单词。

{
    _source: [
        'baseline',
        'cdrp',
        'date',
        'description',
        'dev_status',
        'element',
        'event',
        'id'
    ],
    track_total_hits: true,
    query: {
        bool: {
            filter: [],
            should: [
                {
                    multi_match:{
                        query: "imposed calcs",
                        fields: ["cdrp","description","narrative.*","title","cop"]
                    }
                }
            ]
        } 
    },
    highlight: { fields: { '*': {} } },
    sort: [],
    from: 0,
    size: 50
}

通过运行此查询,我得到以下突出显示的对象。请注意,仅突出显示了“ calcs”一词。如何构建突出显示对象以使ES突出显示“已施加”?

"highlight": {
    "description": [
        "GAP Sub-window conn ONe-e: heve PP-BE Defined ASST requirem RV confsng, des MAN Imposed <em>calcs</em> mising"
    ]
} 
elasticsearch highlight word multiple-matches
1个回答
0
投票

我怀疑您的映射中存在某种设置会阻止匹配,因为我无法使用半默认映射来复制此设置:

PUT highlighter
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "tokenizer": "standard",
          "filter": [
            "lowercase"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "description": {
        "type": "text",
        "fields": {
          "lowercase": {
            "type": "text",
            "analyzer": "my_analyzer"
          }
        }
      }
    }
  }
}

POST highlighter/_doc
{
  "description": "GAP Sub-window conn ONe-e: heve PP-BE Defined ASST requirem RV confsng, des MAN Imposed calcs mising"
}

插入您的查询

GET highlighter/_search
{
  "_source": [
    "baseline",
    "cdrp",
    "date",
    "description",
    "dev_status",
    "element",
    "event",
    "id"
  ],
  "track_total_hits": true,
  "query": {
    "bool": {
      "filter": [],
      "should": [
        {
          "multi_match": {
            "query": "imposed calcs",
            "fields": [
              "cdrp",
              "description.lowercase",
              "narrative.*",
              "title",
              "cop"
            ]
          }
        }
      ]
    }
  },
  "highlight": {
    "fields": {
      "*": {}
    }
  },
  "sort": [],
  "from": 0,
  "size": 50
}

屈服

[
  {
    "_index":"highlighter",
    "_type":"_doc",
    "_id":"Bf5F5HEBW-D5QnrWwTyh",
    "_score":0.5753642,
    "_source":{
      "description":"GAP Sub-window conn ONe-e: heve PP-BE Defined ASST requirem RV confsng, des MAN Imposed calcs mising"
    },
    "highlight":{
      "description":[
        "GAP Sub-window conn ONe-e: heve PP-BE Defined ASST requirem RV confsng, des MAN <em>Imposed</em> <em>calcs</em> mising"
      ]
    }
  }
]
© www.soinside.com 2019 - 2024. All rights reserved.