简体   繁体   English

Elasticsearch查询以选择包含一个字段的值的所有文档多值字段

[英]Elasticsearch query to select all documents where one field's value is contained multi-valued field

Is there a way to query elastic search for all documents that contain the value of one property in the multivalued field; 有没有一种方法可以查询弹性搜索包含多值字段中一个属性值的所有文档; ie: 即:

I have a list of property values in field COLORS: Red, Blue, Black, Green another property has a single value in field PREFERENCE : Red 我在颜色字段中有属性值的列表:红色,蓝色,黑色,绿色另一个属性在字段中具有单个值PREFERENCE:红色

is there a way to select all documents that contain value found in field PREFERENCE within the multi valued field COLORS? 有没有办法选择所有包含多值字段“颜色”中“字段”中包含值的文档?

SQL equivalent would be something of this sort: SQL等效将是这种情况:

SELECT * FROM index WHERE COLORS LIKE CONCAT('%', PREFERENCE, '%')

You could use a script filter. 您可以使用脚本过滤器。 Something like this 像这样

GET /test/stack/_search
{
    "query": {
        "match_all": {}
    },
    "filter": {
        "script":{ 
           "script":"if(doc['colors'].values.indexOf(doc['preference'].value) > -1) true; else false;" ,
           "params": {}

        },"lang":"js"
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 查询所有元素的字段值相同的子文档数组 - Query an array of sub-documents where a field's value is same for all elements 如何访问 javascript 中的多值字典? - How to access multi-valued dictionaries in javascript? 在xml标记值上对ElasticSearch文档进行分组(在字符串字段中) - Grouping ElasticSearch documents on xml tag value (in a string field) 从ElasticSearch中的结果文档中排除字段 - exclude a field from resulted documents in ElasticSearch 如何将 select 包含在数组中的 JSON 字段 - How to select a JSON field contained in an array Postgres:选择json字段数组包含特定值的所有字段吗? - Postgres: Select all fields where json field array contains a particular value? 通过嵌套字段的值选择对象并提取第一级字段 - select object by nested field's value and extract a first level field JQ - 如何 select 字段,条件是该字段的值以另一个字段的值开头 - JQ - how to select field with condition that the field's value starts with another field's value MySQL选择JSON字段属性具有值的位置 - MySQL select where JSON field property has value 获取ElasticSearch中日期直方图上缺少字段的文档计数? - Get count of documents missing a field over a date histogram in ElasticSearch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM