我想使用范圍查詢從 ElasticSearch 回傳資料。我的條件是這樣的。
((Range(Price and Discount) OR Range(Price) AND Filter(Must1) AND Filter(Must2))
我面臨的問題是某些檔案同時包含價格和折扣,但有些檔案只包含價格。我需要一個查詢來根據指定的范圍獲取資料。因此,它回傳折扣欄位,但不回傳我想要的指定范圍。
現在我正在使用這個查詢。
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"bool": {
"must": [
{
"range": {
"discount": {
"gte": 10,
"lte": 12
}
}
},
{
"range": {
"price": {
"gte": 10,
"lte": 12
}
}
}
]
}
},
{
"bool": {
"should": [
{
"range": {
"discount": {
"gte": 10,
"lte": 12
}
}
},
{
"range": {
"price": {
"gte": 10,
"lte": 12
}
}
}
]
}
}
]
}
},
{
"terms": {
"Category": [
"123"
]
}
},
{
"nested": {
"path": "the_path",
"query": {
"bool": {
"must": {
"match": {
}
},
"filter": [
]
}
}
}
}
]
}
}
請幫助我解決這個問題,我從過去幾天開始就一直堅持下去。
uj5u.com熱心網友回復:
根據您給出的條件,將創建以下 DSL 查詢
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"bool": {
"must": [
{
"range": {
"price": {
"gte": 10,
"lte": 20
}
}
},
{
"range": {
"deiscount": {
"gte": 10,
"lte": 20
}
}
}
]
}
},
{
"range": {
"price": {
"gte": 10,
"lte": 20
}
}
}
]
}
},
{
"bool": {
"filter": {
"term": {
"user.id": "kimchy"
}
}
}
},
{
"bool": {
"filter": {
"term": {
"user.id": "kimchy"
}
}
}
}
]
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/456487.html
上一篇:如何在沒有歸一化因子的情況下使用search_analyzer?
下一篇:KibanaDSL或查詢
