gpt4 book ai didi

elasticsearch - 在ElasticSearch中合并过滤器

转载 作者:行者123 更新时间:2023-12-02 22:23:13 27 4
gpt4 key购买 nike

这是基本的 SQL查询,我想将其转换为 elasticsearch 查询,

SELECT product
FROM products
WHERE (price = 200 OR ID = "101")
AND (price != 300)

这是我尝试过的elasticsearch 中的 查询:
GET /my_store/my_product_items/_search

{
"query" : {
"constant_score" : {
"filter" : {
"bool" : {
"must" : [
{ "term" : {"price" : 200}},
{ "term" : {"productID" : "101"}}
],
"must_not" : {
"term" : {"price" : 300}
}
}
}
}
}
}

但是它没有提供与每个SQL查询相同的输出。做支持。

TIA。 :)

最佳答案

好的开始!您只需要用must更改should就可以了:

GET /my_store/my_product_items/_search

{
"query" : {
"constant_score" : {
"filter" : {
"bool" : {
"minimum_should_match": 1, <--- add this
"should" : [ <--- change this
{ "term" : {"price" : 200}},
{ "term" : {"productID" : "101"}}
],
"must_not" : {
"term" : {"price" : 300}
}
}
}
}
}
}

关于elasticsearch - 在ElasticSearch中合并过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43840305/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com