我使用普通荧光笔(Elasticsearch 5.2)。这是一个例子
PUT bookstore
{
"mappings": {
"books": {
"properties": {
"list": {
"properties": {
"summary": {
"type": "text"
},
"title": {
"type": "text"
}
}
}
}
}
}
}
POST bookstore/books/1
{
"list": [
{
"summary": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
"title": "Elasticsearch"
}
]
}
GET bookstore/books/_search
{
"query": {
"simple_query_string": {
"query": "scrambled"
}
},
"highlight": {
"fields": {
"*": {
"require_field_match": false,
"number_of_fragments": 1,
"fragment_size": 70
}
}
}
}
"highlight": {
"list.summary": [
" <em>scrambled</em> it to make a type specimen book. It has survived not only five"
]
}
我的问题是,如何让它以突出显示的单词为中心?在这种情况下,突出显示的单词在开头,在其他情况下在结尾。我怎样才能确保它在中间?
理想情况下,我想要的是指定突出显示的文本之前和之后的标记数,而不是片段大小。
答案 0 :(得分:0)
最后不支持此功能。解决方法是设置number_of_fragments:0
。这将返回整个字段并突出显示。之后,在应用程序级别上应用任何自定义逻辑都很容易。
http://elasticsearch-users.115913.n3.nabble.com/Controlling-highlight-fragments-td1563243.html