字段之间的elasticsearch比较 [英] elasticsearch comparison between fields

查看:19
本文介绍了字段之间的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比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆