Elasticsearch中的嵌套选择查询

编程入门 行业动态 更新时间:2024-10-18 01:34:45
本文介绍了Elasticsearch中的嵌套选择查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我必须在elasticsearch中转换以下查询:

I have to convert the following query in elasticsearch :

select * from index where observable not in (select observable from index where tags = 'whitelist')

我读到应该在非过滤器"中使用过滤器,但是我不知道该怎么做. 谁能帮我? 谢谢

I read that I should use a Filter in a Not Filter but I don't understand how to do. Can anyone help me? Thanks

除了具有"whitelist"标签的标签外,我必须获取所有标签,但是我还需要检查白名单中是否不包含黑名单元素.

I have to get all except those that have 'whitelist' tag but I need to check also that nothing of the blacklist element is contained into the whitelist.

推荐答案

您的SQL查询可以简化为:

Your SQL query can be simplified to this:

select * from index where tags not in ('whitelist')

因此,对应的" ES查询将是

As a result the "corresponding" ES query would be

curl -XPOST localhost:9200/index/_search -d '{ "query": { "filtered": { "filter": { "bool": { "must_not": { "terms": { "tags": [ "whitelist" ] } } } } } } }'

或使用not过滤器而不是bool/must_not的其他过滤器:

or another using the not filter instead of bool/must_not:

curl -XPOST localhost:9200/index/_search -d '{ "query": { "filtered": { "filter": { "not": { "terms": { "tags": [ "whitelist" ] } } } } } }'

更多推荐

Elasticsearch中的嵌套选择查询

本文发布于:2023-10-23 05:35:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519944.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   Elasticsearch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!