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

问题描述

例如MySQL查询

SELECT fields_a, fields_b FROM table WHERE fields_a > fields_b;

我正在努力实现弹性搜索。我已经尝试过,如下所示:

I am trying to implement for elasticsearch. I've tried, as follows:

$where = [ "query" => [ "filter" => [ "script" => [ "script" => "doc[\"fields_a\"].value > doc[\"fields_b\"].value" ] ] ] ];

我缺少什么?

推荐答案

这应该适用于我

{
    "query": {
        "bool": {
            "must": [{
                "script": {
                    "script": "doc['field_a'].value > doc['field_b']"
                }
            }]
        }
    }
}

要仅选择少数字段而不是整个源文档,请使用 stored_fields:[field_a,field_b] ,并确保将这些字段设为

To select only few fields instead of the whole source document use stored_fields "stored_fields": ["field_a","field_b"] and make sure to have those fields as store=true in mappings .

{
stored_fields": ["field_a","field_b"]
    "query": {
        "bool": {
            "must": [{
                "script": {
                    "script": "doc['field_a'].value > doc['field_b']"
                }
            }]
        }
    }
}

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

09-22 04:43