gpt4 book ai didi

elasticsearch - Elasticsearch低于现有领域

转载 作者:行者123 更新时间:2023-12-03 01:45:53 26 4
gpt4 key购买 nike

我有以下 Elasticsearch 结构

[{product: 'product 1', price: 100, originalPrice: 150}]

我该如何进行这样的地方查询(sql): select * from products where price < originalPrice以查找所有具有折扣的产品

最佳答案

最核心的非最佳表现不佳方法是使用 script query,如下所示:

POST /_search
{
"query": {
"bool" : {
"must" : {
"script" : {
"script" : {
"inline": "doc.price.value < doc.originalPrice.value",
"lang": "painless"
}
}
}
}
}
}

更好的方法是在新的 bool(boolean) 字段(即您的情况下的 "discounted": true)中将该信息索引到文档中。
{ 
"product": "product 1",
"price": 100,
"originalPrice": 150,
"discounted": true
}

然后,它将变得更加容易,并进行一个简单的 term查询,此外,它还会运行得更快。
POST /_search
{
"query": {
"bool" : {
"must" : {
"term" : {
"discounted" : true
}
}
}
}
}

关于elasticsearch - Elasticsearch低于现有领域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43995401/

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