gpt4 book ai didi

elasticsearch 字段间比较

转载 作者:行者123 更新时间:2023-11-29 02:44:01 26 4
gpt4 key购买 nike

假设我有包含以下字段的文档:{field1, field2, ... fieldn}

我需要运行一些查询,其中某些条件需要比较两个或多个字段。像 fieldX = fieldY

在标准 SQL 中,示例可能是:

SELECT * FROM Table1 WHERE farePrice>100 AND originRegion = destinationRegion 

我一直在阅读一些文档,看起来“编写脚本”可能是实现此目标的唯一方法?或者还有其他选择吗?

最佳答案

您可以使用脚本过滤器 -

{
"filtered": {
"query": {
"range": {
"farePrice": {
"gt": 100
}
}
},
"filter": {
"script": {
"script": "doc['originRegion'].value == doc['destinationRegion'].value"
}
}
}
}

您可以在 here 找到更多信息。和 here .

关于elasticsearch 字段间比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27708612/

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