我有一個帶有多個資料范圍過濾器的過濾器,帶有 And 和 OR 運算子。我必須獲得滿足日期范圍過濾器或任何一個日期范圍過濾器的過濾器結果。
"query":{
"bool" : {
"must" : [
{
"match_phrase_prefix" : {
"searchField" : {
"query" : "Adam",
"slop" : 0,
"max_expansions" : 50,
"boost" : 1.0
}
}
}
],
"filter" : [
{
"term" : {
"srvcType" : {
"value" : "FullTime",
"boost" : 1.0
}
}
},
{"range" : { "or": {"startDt": {"from" : "2010-05-16","to" : "2022-02-18","include_lower": true,"include_upper" : true,"boost" : 1.0}} }},
{"range" : { "or": {"endDt": {"from" : "2015-05-16","to" : "2022-02-18","include_lower" : true,"include_upper" : true,"boost" : 1.0}}}}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
}
我嘗試像上面那樣運行查詢,我得到了 parsing_exception - 查詢不支持 StartDt。
{
"query":{
"bool" : {
"must" : [
{
"match_phrase_prefix" : {
"searchField" : {
"query" : "Adam",
"slop" : 0,
"max_expansions" : 50,
"boost" : 1.0
}
}
}
],
"filter" : [
{
"term" : {
"srvcType" : {
"value" : "FullTime",
"boost" : 1.0
}
}
},
{"range" : {"startDt": {"from" : "2010-05-16","to" : "2022-02-18","include_lower": true,"include_upper" : true,"boost" : 1.0}} },
{"range" : {"endDt": {"from" : "2015-05-16","to" : "2022-02-18","include_lower" : true,"include_upper" : true,"boost" : 1.0}}}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
}
uj5u.com熱心網友回復:
如果您的日期范圍過濾器需要 AND 語意,您可以讓陣列range中的兩個查詢。bool/filter
但是,如果您需要 OR 語意,您可以使用bool/should查詢,如下所示:
{
"query": {
"bool": {
"must": [
{
"match_phrase_prefix": {
"searchField": {
"query": "Adam",
"slop": 0,
"max_expansions": 50,
"boost": 1
}
}
}
],
"filter": [
{
"term": {
"srvcType": {
"value": "FullTime",
"boost": 1
}
}
}
],
"minimum_should_match": 1,
"should": [
{
"range": {
"startDt": {
"from": "2010-05-16",
"to": "2022-02-18",
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
},
{
"range": {
"endDt": {
"from": "2015-05-16",
"to": "2022-02-18",
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/430710.html
上一篇:彈性搜索詞查詢不適用于特定欄位
