[英]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.