elasticsearch / lucene highlight

左心房为你撑大大i 提交于 2020-01-03 09:42:11

问题


I'm using ElasticSearch to index documents.

My mapping is:

"mongodocid": {
  "boost": 1.0,
  "store": "yes",
  "type": "string"
},
"fulltext": {
  "boost": 1.0,
  "index": "analyzed",
  "store": "yes",
  "type": "string",
  "term_vector": "with_positions_offsets"
}

To highlight the complete fulltext I am setting number_of_framgments to 0.

If I do the following Lucene-like string query:

{
  "highlight": {
    "pre_tags": "<b>",
    "fields": {
      "fulltext": {
        "number_of_fragments": 0
      }
    },
    "post_tags": "</b>"
  },
  "query": {
    "query_string": {
      "query": "fulltext:test"
    }
  },
  "size": 100
}

For some documents in the result set the length of the highlighted fulltext is smaller than the fulltext itself. Since I am setting number_of_fragments to 0 and pre_tags/post_tags are added this should not happen.

Now comes the strange behaviour: If I only search for one of the failing elements by doing this:

{
  "highlight": {
    "pre_tags": "<b>",
    "fields": {
      "fulltext": {
        "number_of_fragments": 0
      }
    },
    "post_tags": "</b>"
  },
  "query": {
    "query_string": {
      "query": "fulltext:test AND mongodocid:4d0a861c2ebef6032c00b1ec"
    }
  },
  "size": 100
}

then all works fine.

Any ideas?


回答1:


Sounds like issue which has been fixed in 0.14.0 (see #479). As of writing the 0.14.0 hasn't been released yet, can you try master?



来源:https://stackoverflow.com/questions/4512656/elasticsearch-lucene-highlight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!