弹性搜索比较领域 [英] elasticsearch comparison between fields

查看:114
本文介绍了弹性搜索比较领域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



在标准SQL中,一个例子可以是:

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

我正在阅读一些文档,看起来脚本可能是实现这一点的唯一方法?还是有其他选择?

解决方案

您可以使用脚本过滤器 -



pre $ {
过滤:{
查询:{
范围:{
farePrice
gt:100
}
}
},
过滤器:{
脚本:{
脚本 :doc ['originRegion']。value == doc ['destinationRegion']。value
}
}
}
}

您可以在 here 这里


Let's say I have documents with the following fields: {field1, field2, ... fieldn}

I need to run some queries where some of the conditions will require a comparison between two or more fields. like fieldX = fieldY

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"
      }
    }
  }
}

You can find more information at here and here .

这篇关于弹性搜索比较领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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