[英]Multiple match_phrase conditions with another bool in a single ElasticSearch query?
我正在嘗試進行 Elasticsearch 查詢,該查詢搜索文本字段(“body”)並返回至少與我提供的兩個多詞短語之一匹配的項目(即:“stack overflow”或“the stackoverflow”)。 我還希望查詢只提供在給定時間戳之后發生的結果,結果按時間排序。
我目前的解決方案如下。 我相信 MUST 工作正常(gte 時間戳),但是帶有兩個 match_phrases 的 BOOL + SHOULD 是不正確的。 我收到以下錯誤:
Unexpected character ('{' (code 123)): was expecting double-quote to start field name
我認為這是因為我有兩個 match_phrases 嗎?
這是 ES 映射,我正在使用的 ES API 的詳細信息在這里。
{"query":
{"bool":
{"should":
[{"match_phrase":
{"body":"a+phrase"}
},
{"match_phrase":
{"body":"another+phrase"}
}
]
},
{"bool":
{"must":
[{"range":
{"created_at:
{"gte":"thispage"}
}
}
]}
}
},"size":10000,
"sort":"created_at"
}
我認為您只是在created_at
之后遺漏了一個"
。
{
"query": {
"bool": {
"must": [
{
"range": {
"created_at": {
"gte": "1534004694"
}
}
},
{
"bool": {
"should": [
{
"match_phrase": {
"body": "a+phrase"
}
},
{
"match_phrase": {
"body": "another+phrase"
}
}
]
}
}
]
}
},
"size": 10,
"sort": "created_at"
}
此外,您可以同時擁有must
和should
作為bool
object 的屬性,因此這也值得一試。
{
"query": {
"bool": {
"must": {
"range": {
"created_at": {
"gte": "1534004694"
}
}
},
"should": [
{
"match_phrase": {
"body": "a+phrase"
}
},
{
"match_phrase": {
"body": "another+phrase"
}
}
]
}
},
"size": 10,
"sort": "created_at"
}
附帶說明一下,Postman 或任何 JSON 格式化程序/驗證程序確實有助於確定錯誤所在。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.