elasticsearch - Elastics 搜索查询过滤掉列表中值为 A 但不是 B 的结果
问题描述
我正在尝试形成一个查询,要求仅过滤国家为印度而不是美国的数据。
样本数据。
{
"data": {
"attributes": {
"name": "test",
"country": ["india","usa","japan"]
}
}
}
因为,在上面的例子中,我们有印度和美国,它不应该过滤结果。
而如果数据采用下面提到的格式,它应该过滤。
例1:
{
"data": {
"attributes": {
"name": "test",
"country": ["india","japan"]
}
}
}
例 2:
{
"data": {
"attributes": {
"name": "test",
"country": ["india"]
}
}
}
解决方案
这个问题,看起来有点混乱。我假设,你不希望印度和美国走到一起。基于上述假设,共享以下查询。
"query": {
"bool": {
"must": [{
"term": {
"tags": {
"value": "india"
}
}
}
],
"must_not": [{
"term": {
"tags": {
"value": "usa"
}
}
}
]
}
}
推荐阅读
- excel - EXCEL - 根据 ID 组合行,不会丢失跨列分布的数据
- reactjs - React 给出的“URLSearchParams”在 Edge v38 中未定义
- c# - 在 WriteLine 中突出显示文本
- javascript - 如何使 Service Worker 与通配符子域兼容?
- node.js - AWS Lambda 层 - 打字稿 - 在索引处理程序中指定导入时出现问题,因为在层中,然后需要采用 /opt/nodejs/ 形式
- python - SVM 的标准化数据 - Scikit-learn/Python
- android - 在XML Shape Android Studio的LayerList中使用位图时PNG透明背景显示为黑色
- docker - 从 docker compose 中的网络别名中删除服务名称
- python - numpy 2d:如何仅获取第二列中允许的值的第一列中最大元素的索引
- java - Eclipse(java testing) - 终止突变版本