本文介绍了字段之间的elasticsearch比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有包含以下字段的文档:{field1, field2, ... fieldn}
Let's say I have documents with the following fields: {field1, field2, ... fieldn}
我需要运行一些查询,其中某些条件需要在两个或多个字段之间进行比较.像 fieldX = fieldY
I need to run some queries where some of the conditions will require a comparison between two or more fields. like fieldX = fieldY
在标准 SQL 中,一个例子可能是:
In standard SQL, an example could be:
SELECT * FROM Table1 WHERE farePrice>100 AND originRegion = destinationRegion我一直在阅读一些文档,看起来脚本"可能是实现这一目标的唯一方法?或者还有其他选择吗?
I'be been reading some documentation, and it looks "scripting" could be the only way to achieve this? Or are there any other options?
推荐答案可以使用脚本过滤器 -
You can use the script filter -
{ "filtered": { "query": { "range": { "farePrice": { "gt": 100 } } }, "filter": { "script": { "script": "doc['originRegion'].value == doc['destinationRegion'].value" } } } }您可以在 这里 和 这里.
更多推荐
字段之间的elasticsearch比较
发布评论