文章目录

  • 一、问题描述
  • 二、错误示例
  • 三、正确示例

一、问题描述

在使用ElasticSearch进行查询的时候,发现nested数据在使用must_not时不生效,可以查出所有数据。

index中的mapping

{"product" : {"mappings" : {"properties" : {"attrs" : {"type" : "nested","properties" : {"attrId" : {"type" : "long"},"attrName" : {"type" : "keyword"},"attrValue" : {"type" : "keyword"}}},"brandId" : {"type" : "long"},"brandImg" : {"type" : "keyword"},"brandName" : {"type" : "keyword"},"catalogId" : {"type" : "long"},"catalogName" : {"type" : "keyword"},"catelogId" : {"type" : "long"},"hasStock" : {"type" : "boolean"},"hotScore" : {"type" : "long"},"saleCount" : {"type" : "long"},"skuId" : {"type" : "long"},"skuImg" : {"type" : "keyword"},"skuPrice" : {"type" : "keyword"},"skuTitle" : {"type" : "text","analyzer" : "ik_smart"},"spuId" : {"type" : "keyword"}}}}
}

index中的数据

{"took" : 0,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 9,"relation" : "eq"},"max_score" : 1.0,"hits" : [{"_index" : "product","_type" : "_doc","_id" : "1","_score" : 1.0,"_source" : {"attrs" : [{"attrId" : 2,"attrName" : "上市年份","attrValue" : "2020"},{"attrId" : 3,"attrName" : "颜色","attrValue" : "流光幻镜"},{"attrId" : 1,"attrName" : "入网参数","attrValue" : "5G"},{"attrId" : 9,"attrName" : "电池容量","attrValue" : "5000mAh"},{"attrId" : 10,"attrName" : "机身长度(mm)","attrValue" : "168"},{"attrId" : 7,"attrName" : "CPU型号","attrValue" : "麒麟990"},{"attrId" : 8,"attrName" : "CPU工艺","attrValue" : "5nm"},{"attrId" : 12,"attrName" : "CPU品牌","attrValue" : "海思(Hisilicon)"}],"brandId" : 2,"brandImg" : "https://caiflower.oss-cn-beijing.aliyuncs.com/2022-04-26/32830b43-4eee-45e0-8acc-a165d51f65cb_Huawei.svg.png","brandName" : "华为","catalogId" : 225,"catalogName" : "手机","hasStock" : true,"hotScore" : 0,"saleCount" : 2654,"skuId" : 1,"skuImg" : "https://mall-fire.oss-cn-shenzhen.aliyuncs.com/2020-06-05/e5ba78ec-9cf5-4bbd-86a7-ad2f611e2512_图集1.jpg","skuPrice" : 8888.0,"skuTitle" : "华为 HUAWEI P40 Pro+ 麒麟990 5G  流光幻镜 套餐二 麒麟990 5G SoC芯片 5000万超感知徕卡五摄 100倍双目变焦 全网通5G","spuId" : 3}},{"_index" : "product","_type" : "_doc","_id" : "2","_score" : 1.0,"_source" : {"attrs" : [{"attrId" : 2,"attrName" : "上市年份","attrValue" : "2020"},{"attrId" : 3,"attrName" : "颜色","attrValue" : "流光幻镜"},{"attrId" : 1,"attrName" : "入网参数","attrValue" : "5G"},{"attrId" : 9,"attrName" : "电池容量","attrValue" : "5000mAh"},{"attrId" : 10,"attrName" : "机身长度(mm)","attrValue" : "168"},{"attrId" : 7,"attrName" : "CPU型号","attrValue" : "麒麟990"},{"attrId" : 8,"attrName" : "CPU工艺","attrValue" : "5nm"},{"attrId" : 12,"attrName" : "CPU品牌","attrValue" : "海思(Hisilicon)"}],"brandId" : 2,"brandImg" : "https://caiflower.oss-cn-beijing.aliyuncs.com/2022-04-26/32830b43-4eee-45e0-8acc-a165d51f65cb_Huawei.svg.png","brandName" : "华为","catalogId" : 225,"catalogName" : "手机","hasStock" : true,"hotScore" : 0,"saleCount" : 1454,"skuId" : 2,"skuImg" : "https://mall-fire.oss-cn-shenzhen.aliyuncs.com/2020-06-05/9915d4a7-9f73-4c71-85cc-65c0b7f644dd_图集2.jpg","skuPrice" : 8888.0,"skuTitle" : "华为 HUAWEI P40 Pro+ 麒麟990 5G  流光幻镜 套餐二 麒麟990 5G SoC芯片 5000万超感知徕卡五摄 100倍双目变焦 全网通5G","spuId" : 3}},{"_index" : "product","_type" : "_doc","_id" : "3","_score" : 1.0,"_source" : {"attrs" : [{"attrId" : 2,"attrName" : "上市年份","attrValue" : "2020"},{"attrId" : 3,"attrName" : "颜色","attrValue" : "流光幻镜"},{"attrId" : 1,"attrName" : "入网参数","attrValue" : "5G"},{"attrId" : 9,"attrName" : "电池容量","attrValue" : "5000mAh"},{"attrId" : 10,"attrName" : "机身长度(mm)","attrValue" : "168"},{"attrId" : 7,"attrName" : "CPU型号","attrValue" : "麒麟990"},{"attrId" : 8,"attrName" : "CPU工艺","attrValue" : "5nm"},{"attrId" : 12,"attrName" : "CPU品牌","attrValue" : "海思(Hisilicon)"}],"brandId" : 2,"brandImg" : "https://caiflower.oss-cn-beijing.aliyuncs.com/2022-04-26/32830b43-4eee-45e0-8acc-a165d51f65cb_Huawei.svg.png","brandName" : "华为","catalogId" : 225,"catalogName" : "手机","hasStock" : true,"hotScore" : 0,"saleCount" : 1673,"skuId" : 3,"skuImg" : "https://mall-fire.oss-cn-shenzhen.aliyuncs.com/2020-06-05/4d2ed8b5-5504-4bad-8620-75db9c29d3ea_图集4.jpg","skuPrice" : 5988.0,"skuTitle" : "华为 HUAWEI P40 Pro+ 麒麟990 5G  流光幻镜 套餐二 麒麟990 5G SoC芯片 5000万超感知徕卡五摄 100倍双目变焦 全网通5G","spuId" : 3}},{"_index" : "product","_type" : "_doc","_id" : "4","_score" : 1.0,"_source" : {"attrs" : [{"attrId" : 2,"attrName" : "上市年份","attrValue" : "2020"},{"attrId" : 3,"attrName" : "颜色","attrValue" : "流光幻镜"},{"attrId" : 1,"attrName" : "入网参数","attrValue" : "5G"},{"attrId" : 9,"attrName" : "电池容量","attrValue" : "5000mAh"},{"attrId" : 10,"attrName" : "机身长度(mm)","attrValue" : "168"},{"attrId" : 7,"attrName" : "CPU型号","attrValue" : "麒麟990"},{"attrId" : 8,"attrName" : "CPU工艺","attrValue" : "5nm"},{"attrId" : 12,"attrName" : "CPU品牌","attrValue" : "海思(Hisilicon)"}],"brandId" : 2,"brandImg" : "https://caiflower.oss-cn-beijing.aliyuncs.com/2022-04-26/32830b43-4eee-45e0-8acc-a165d51f65cb_Huawei.svg.png","brandName" : "华为","catalogId" : 225,"catalogName" : "手机","hasStock" : true,"hotScore" : 0,"saleCount" : 3587,"skuId" : 4,"skuImg" : "https://mall-fire.oss-cn-shenzhen.aliyuncs.com/2020-06-05/55871b9f-589b-4957-8eb3-9d2c8698406b_图集6.jpg","skuPrice" : 5988.0,"skuTitle" : "华为 HUAWEI P40 Pro+ 麒麟990 5G  霓影紫 套餐二 麒麟990 5G SoC芯片 5000万超感知徕卡四摄 50倍数字变焦  全网通5G手机","spuId" : 3}},{"_index" : "product","_type" : "_doc","_id" : "5","_score" : 1.0,"_source" : {"attrs" : [{"attrId" : 2,"attrName" : "上市年份","attrValue" : "2020"},{"attrId" : 3,"attrName" : "颜色","attrValue" : "流光幻镜"},{"attrId" : 1,"attrName" : "入网参数","attrValue" : "5G"},{"attrId" : 9,"attrName" : "电池容量","attrValue" : "5000mAh"},{"attrId" : 10,"attrName" : "机身长度(mm)","attrValue" : "168"},{"attrId" : 7,"attrName" : "CPU型号","attrValue" : "麒麟990"},{"attrId" : 8,"attrName" : "CPU工艺","attrValue" : "5nm"},{"attrId" : 12,"attrName" : "CPU品牌","attrValue" : "海思(Hisilicon)"}],"brandId" : 2,"brandImg" : "https://caiflower.oss-cn-beijing.aliyuncs.com/2022-04-26/32830b43-4eee-45e0-8acc-a165d51f65cb_Huawei.svg.png","brandName" : "华为","catalogId" : 225,"catalogName" : "手机","hasStock" : true,"hotScore" : 0,"saleCount" : 1235,"skuId" : 5,"skuImg" : "https://mall-fire.oss-cn-shenzhen.aliyuncs.com/2020-06-05/0bb896b8-fee8-4933-877c-2c4615c802d6_图集7.jpg","skuPrice" : 5988.0,"skuTitle" : "华为 HUAWEI P40 Pro+ 麒麟990 5G  霓影紫 套餐二 麒麟990 5G SoC芯片 5000万超感知徕卡四摄 50倍数字变焦  全网通5G手机","spuId" : 3}},{"_index" : "product","_type" : "_doc","_id" : "6","_score" : 1.0,"_source" : {"attrs" : [{"attrId" : 2,"attrName" : "上市年份","attrValue" : "2020"},{"attrId" : 3,"attrName" : "颜色","attrValue" : "流光幻镜"},{"attrId" : 1,"attrName" : "入网参数","attrValue" : "5G"},{"attrId" : 9,"attrName" : "电池容量","attrValue" : "5000mAh"},{"attrId" : 10,"attrName" : "机身长度(mm)","attrValue" : "168"},{"attrId" : 7,"attrName" : "CPU型号","attrValue" : "麒麟990"},{"attrId" : 8,"attrName" : "CPU工艺","attrValue" : "5nm"},{"attrId" : 12,"attrName" : "CPU品牌","attrValue" : "海思(Hisilicon)"}],"brandId" : 2,"brandImg" : "https://caiflower.oss-cn-beijing.aliyuncs.com/2022-04-26/32830b43-4eee-45e0-8acc-a165d51f65cb_Huawei.svg.png","brandName" : "华为","catalogId" : 225,"catalogName" : "手机","hasStock" : true,"hotScore" : 0,"saleCount" : 1456,"skuId" : 6,"skuImg" : "https://mall-fire.oss-cn-shenzhen.aliyuncs.com/2020-06-05/72b3962b-6a79-4d16-8c83-2f3f61dba176_图集5.jpg","skuPrice" : 5988.0,"skuTitle" : "华为 HUAWEI P40 Pro+ 麒麟990 5G  霓影紫 套餐二 麒麟990 5G SoC芯片 5000万超感知徕卡四摄 50倍数字变焦  全网通5G手机","spuId" : 3}},{"_index" : "product","_type" : "_doc","_id" : "7","_score" : 1.0,"_source" : {"attrs" : [{"attrId" : 2,"attrName" : "上市年份","attrValue" : "2020"},{"attrId" : 3,"attrName" : "颜色","attrValue" : "流光幻镜"},{"attrId" : 1,"attrName" : "入网参数","attrValue" : "5G"},{"attrId" : 9,"attrName" : "电池容量","attrValue" : "5000mAh"},{"attrId" : 10,"attrName" : "机身长度(mm)","attrValue" : "168"},{"attrId" : 7,"attrName" : "CPU型号","attrValue" : "麒麟990"},{"attrId" : 8,"attrName" : "CPU工艺","attrValue" : "5nm"},{"attrId" : 12,"attrName" : "CPU品牌","attrValue" : "海思(Hisilicon)"}],"brandId" : 2,"brandImg" : "https://caiflower.oss-cn-beijing.aliyuncs.com/2022-04-26/32830b43-4eee-45e0-8acc-a165d51f65cb_Huawei.svg.png","brandName" : "华为","catalogId" : 225,"catalogName" : "手机","hasStock" : true,"hotScore" : 0,"saleCount" : 2354,"skuId" : 7,"skuImg" : "https://mall-fire.oss-cn-shenzhen.aliyuncs.com/2020-06-05/9915d4a7-9f73-4c71-85cc-65c0b7f644dd_图集2.jpg","skuPrice" : 5988.0,"skuTitle" : "华为 HUAWEI P40 Pro+ 麒麟990 5G  钛空银 套餐二 【白条12期免息送碎屏险】华为 P40 Pro 5G手机 分期","spuId" : 3}},{"_index" : "product","_type" : "_doc","_id" : "8","_score" : 1.0,"_source" : {"attrs" : [{"attrId" : 2,"attrName" : "上市年份","attrValue" : "2020"},{"attrId" : 3,"attrName" : "颜色","attrValue" : "流光幻镜"},{"attrId" : 1,"attrName" : "入网参数","attrValue" : "5G"},{"attrId" : 9,"attrName" : "电池容量","attrValue" : "5000mAh"},{"attrId" : 10,"attrName" : "机身长度(mm)","attrValue" : "168"},{"attrId" : 7,"attrName" : "CPU型号","attrValue" : "麒麟990"},{"attrId" : 8,"attrName" : "CPU工艺","attrValue" : "5nm"},{"attrId" : 12,"attrName" : "CPU品牌","attrValue" : "海思(Hisilicon)"}],"brandId" : 2,"brandImg" : "https://caiflower.oss-cn-beijing.aliyuncs.com/2022-04-26/32830b43-4eee-45e0-8acc-a165d51f65cb_Huawei.svg.png","brandName" : "华为","catalogId" : 225,"catalogName" : "手机","hasStock" : true,"hotScore" : 0,"saleCount" : 2546,"skuId" : 8,"skuImg" : "https://mall-fire.oss-cn-shenzhen.aliyuncs.com/2020-06-05/0bb896b8-fee8-4933-877c-2c4615c802d6_图集7.jpg","skuPrice" : 5988.0,"skuTitle" : "华为 HUAWEI P40 Pro+ 麒麟990 5G  钛空银 套餐三 【白条12期免息送碎屏险】华为 P40 Pro 5G手机 分期","spuId" : 3}},{"_index" : "product","_type" : "_doc","_id" : "9","_score" : 1.0,"_source" : {"attrs" : [{"attrId" : 2,"attrName" : "上市年份","attrValue" : "2020"},{"attrId" : 3,"attrName" : "颜色","attrValue" : "流光幻镜"},{"attrId" : 1,"attrName" : "入网参数","attrValue" : "5G"},{"attrId" : 9,"attrName" : "电池容量","attrValue" : "5000mAh"},{"attrId" : 10,"attrName" : "机身长度(mm)","attrValue" : "168"},{"attrId" : 7,"attrName" : "CPU型号","attrValue" : "麒麟990"},{"attrId" : 8,"attrName" : "CPU工艺","attrValue" : "5nm"},{"attrId" : 12,"attrName" : "CPU品牌","attrValue" : "海思(Hisilicon)"}],"brandId" : 2,"brandImg" : "https://caiflower.oss-cn-beijing.aliyuncs.com/2022-04-26/32830b43-4eee-45e0-8acc-a165d51f65cb_Huawei.svg.png","brandName" : "华为","catalogId" : 225,"catalogName" : "手机","hasStock" : true,"hotScore" : 0,"saleCount" : 957,"skuId" : 9,"skuImg" : "https://mall-fire.oss-cn-shenzhen.aliyuncs.com/2020-06-05/e5ba78ec-9cf5-4bbd-86a7-ad2f611e2512_图集1.jpg","skuPrice" : 4188.0,"skuTitle" : "华为 HUAWEI P40 Pro+ 麒麟990 5G  钛空银 套餐一 【白条12期免息送碎屏险】华为 P40 Pro 5G手机 分期","spuId" : 3}}]}
}

二、错误示例

GET product/_search
{"query": {"bool": {"must": [{"nested": {"path": "attrs","query": {"bool": {"must_not": [{"term": {"attrs.attrId": 7}},{"term": {"attrs.attrValue": "麒麟990"}}]}}}}]}}
}

结果数据全部命中

三、正确示例

GET product/_search
{"query": {"bool": {"must_not": [{"nested": {"path": "attrs","query": {"bool": {"must": [{"term": {"attrs.attrId": 7}},{"term": {"attrs.attrValue": "麒麟990"}}]}}}}]}}
}

无数据命中

为什么es中nested数据must_not不生效?相关推荐

  1. win下配置的ES中的数据在哪里可以看到?三种方式你看那种更加高大上!!!(win_Elasticsearch)

    在上一篇博客<使用logstash将Mysql中的数据导入到ElasticSearch中(详细步骤,win_Elasticsearch)>中我们提到将数据插入到es中,那我怎么知道数据是否 ...

  2. 把json数据导入linux,使用json文件给es中导入数据

    使用json文件可以给es中导入数据,10万条左右的数据可以一次导入,数量太大时导入就会报错.大数量的到导入还是需要用bulk方式. accounts.json文件格式如下: {"index ...

  3. MySQL数据库数据导入ES中

    需要安装 mysql数据导入ES中,用到的有logstash,ES,mysql的连接包.链接:https://pan.baidu.com/s/1xopMMUtPir12zrQfYcwBZg  提取码: ...

  4. es重建字段类型_关于elasticsearch中更新数据的几种方式

    作为一个成熟的框架,Elasticsearch里面提供了丰富的操作数据的api,本篇我们就来学习一下在es中更新数据的几种方式. (一)更新文档 (1)部分更新: java api: ` HashMa ...

  5. es中的dsl练习题-----简单的dsl语句

    slirp4netns >= 0.4 fuse-overlayfs >= 0.7 这是在本地安装elasticsearch数据然后通过kibana来操作数据的dsl来实现的 其中的查询ap ...

  6. es中修改某个字段值_搜索引擎之laravel中使用elasticsearch(一)

    一.概述 Elasticsearch官方提供了Composer包可直接引用就好,不过要注意:如果你使用的elastcsearch不是最新的那么我建议你指定合适的版本下载,而不要采用最新的,因为不同版本 ...

  7. es中主分片和副本分片

    我们知道es中保存数据的时候是有主分片和副本分片的,那么副本分片的作用有哪些呢? 1.作为备份,防止主分片崩溃 2.分担查询请求,请求会在主分片和副本分片之间均匀分布 第一点:主副本之前角色的切换如何 ...

  8. java post和put的区别,ES 中的 POST 和 PUT 的区别

    0.什么是Restful架构 比较难说清楚,这部分大雾状态,引ruanyf 理解RESTful架构 的几句总结吧: Fielding将他对互联网软件的架构原则,定名为REST,即Representat ...

  9. Elasticsearch——使用Java API实现ES中的索引、映射、文档操作

    文章目录: 1.开篇 2.案例详解 2.1 创建ES客户端:完成与ES服务端的连接 2.2 创建索引 2.3 查看索引 2.4 删除索引 2.5 创建文档 2.6 修改文档 2.7 查看文档 2.8 ...

最新文章

  1. 解决MyBatis中 Could not set property ~ o f ~异常
  2. Redis在C#中的使用及Redis的封装
  3. 此文一出,从此无需再熬夜等待
  4. BZOJ 1968 [Ahoi2005]COMMON 约数研究
  5. jvm(8)-虚拟机字节码执行引擎
  6. L1-013.计算阶乘和
  7. SpringCloud工作笔记040--- XMLHTTP中setRequestHeader()方法解析
  8. NumPy 基础入门
  9. 牛客小白月赛9: div.2 A(线性筛)
  10. 文献翻译:《弱监督学习实现3D人脸重建:从单张图片到图片集》(Accurate 3D Face Reconstruction with Weakly-Supervised Learning)
  11. @Transaction注解详解
  12. three.js自定义材质各向异性
  13. 一次微信小程序的问题跟踪记录
  14. 【新知实验室】手把手实现腾讯云音视频应用
  15. 【UFUN开发板评测】小巧而不失精致,简单而不失内涵——uFun开发板开箱爆照...
  16. Linux 系统增加硬盘
  17. IIS WEB服务器
  18. 【模型评价指标】分析模型评价常用指标
  19. java遍历易百教程_Java PrintStream类示例
  20. CondaIOError: Missing write permissions in: C:\ProgramData\Anaconda3

热门文章

  1. 锐达又出新型设备:【钢结构抛丸机】
  2. 关闭 macOS Microsoft Autoupdate程序
  3. 计算机辅助教育cbe不包括,计算机辅助教育复习资料之一
  4. 如何将手机中的照片制作成视频?想不到方法这么简单,涨知识了
  5. Office 2013 Word ,Excel或者PPT打开时出现 VBE6EXT.OLB不能被加载,溢出的问题解决
  6. bugku ctf 闪电十六鞭 <?= ?> 短标签
  7. C# .net 数组倒序排序
  8. 3400 Star!知名日程安排工具的开源替代品
  9. 【漏洞学习——XML注入】高德导航某接口XML实体注入
  10. 计算机图形编程基础,Windows图形编程基础.ppt