我不能用这个来突出我的生活。对于在过滤子句中提到的字段上突出显示,似乎弹性搜索被打破了。以下查询只是没有突出显示。这是Elastic的一个问题吗?我能做些什么才能做到这一点?
{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"term": {
"language": "Austrian"
}
}
]
}
},
"filter": {
"and": [
{
"query": {
"query_string": {
"fields": [
"standard_analyzed_name",
"standard_analyzed_message"
],
"query": "Arnold AND Schwarz"
}
}
}
]
}
}
},
"size": 20,
"sort": [
{
"total_interactions": {
"order": "desc"
}
}
],
"highlight": {
"fields": {
"standard_analyzed_name": {
"pre_tags": [
"<strong>"
],
"post_tags": [
"</strong>"
],
"fragment_size": 500,
"number_of_fragments": 1
},
"standard_analyzed_message": {
"pre_tags": [
"<strong>"
],
"post_tags": [
"</strong>"
],
"fragment_size": 500,
"number_of_fragments": 1
}
}
}
}
更新
以上查询在弹性搜索2.0.0中突出显示 - Yayyy
答案 0 :(得分:1)
嗯,简单地说,你已经交换了query
和filter
部分。您的query_string
应该进入query
部分而term
应该进入filter
部分,然后一切都会很好,您将看到突出显示的字段。
{
"query": {
"filtered": {
"query": {
"query_string": {
"fields": [
"standard_analyzed_name",
"standard_analyzed_message"
],
"query": "arnold"
}
},
"filter": {
"term": {
"language": "austrian"
}
}
}
},
"size": 20,
"sort": [
{
"total_interactions": {
"order": "desc"
}
}
],
"highlight": {
"fields": {
"standard_analyzed_name": {
"pre_tags": [
"<strong>"
],
"post_tags": [
"</strong>"
],
"fragment_size": 500,
"number_of_fragments": 3
},
"standard_analyzed_message": {
"pre_tags": [
"<strong>"
],
"post_tags": [
"</strong>"
],
"fragment_size": 500,
"number_of_fragments": 3
}
}
}
}