[英]ElasticSearch highlight with filter query
我有以下查詢,但突出顯示不起作用。
{
"query": {
"filtered" : {
"filter" : {
"or" : {
"filters" : [
{
"query": {
"multi_match":{
"query":"time",
"fields":[
"display_name_en","display_name_pa","display_name_pr",
"icon_class","in_sidemenu","model_name","name",
"table_name"
],
"operator":"OR"
}
}
},
{
"terms":{
"created_by.id":["11","13","14","16"],
"_name" : "created_by"
}
},
{
"range":{
"created_at":{
"gte":"2016-01-27",
"lte":"2016-03-21",
"format":"YYYY-MM-dd"
}
}
}
],
"_name" : "or"
}
}
}
},
"highlight": {
"fields" : {
"name" : {}
}
}
}
結果是這樣的:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "promote_kmp",
"_type": "resources",
"_id": "569e0d84684cc",
"_score": 1,
"_source": {
"id": 106,
"name": "Last time First Update",
"display_name_en": "Last time",
"display_name_pr": "Last time",
"display_name_pa": "Last time",
"table_name": "Last time",
"model_name": "Last time",
"in_sidemenu": "0",
"icon_class": "Last time",
"created_at": "2016-01-18 09:40:51",
"created_by": null,
"updated_at": "2016-01-19 14:48:44",
"updated_by": {
"id": 6,
"first_name": "Laili",
"last_name": "Hamta",
"last_activity": "2016-01-19 14:48:44",
"roles": [
{
"id": 1,
"name": "admin",
"created_at": "2015-09-06 15:19:15",
"updated_at": "2015-09-06 15:19:15",
"pivot": {
"user_id": 6,
"role_id": 1
}
}
]
}
},
"matched_queries": [
"or"
]
}
]
}
}
如您所見,結果中沒有任何高亮關鍵字,那么此查詢有什么錯誤,為什么高亮不起作用? 但是,如果我將multi_match
部分放在filter:{}
之前,那么它就可以工作,在這種情況下,如何與with or
operator一起使用? 任何幫助謝謝。
查詢的問題在於您僅 filtering
結果, highlight
僅適用於queries
。 您還可以注意到,由於僅應用了filters
,每個文檔的score
均為1。 您需要像這樣重寫查詢
{
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "time",
"fields": [
"display_name_en",
"display_name_pa",
"display_name_pr",
"icon_class",
"in_sidemenu",
"model_name",
"name",
"table_name"
]
}
},
{
"terms": {
"created_by.id": [
"11",
"13",
"14",
"16"
],
"_name": "created_by"
}
},
{
"range": {
"created_at": {
"gte": "2016-01-27",
"lte": "2016-03-21",
"format": "YYYY-MM-dd"
}
}
}
]
}
},
"highlight": {
"fields": {}
}
}
將bool should clause
轉換or filters
轉換為bool should clause
,突出顯示即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.