繁体   English   中英

如何在Elasticsearch中的嵌套文档中搜索精确文本

[英]How to search exact text in nested document in elasticsearch

我有这样的索引,

        "_index": "test",
        "_type": "products",
        "_id": "URpYIFBAQRiPPu1BFOZiQg",
        "_score": null,
        "_source": {

           "currency": null,
           "colors": [],
           "api": 1,
           "sku": 9999227900050002,               
           "category_path": [
              {
                 "id": "cat00000",
                 "name": "B1"
              },
              {
                 "id": "abcat0400000",
                 "name": "Cameras & Camcorders"
              },
              {
                 "id": "abcat0401000",
                 "name": "Digital Cameras"
              },
              {
                 "id": "abcat0401005",
                 "name": "Digital SLR Cameras"
              },
              {
                 "id": "pcmcat180400050006",
                 "name": "DSLR Package Deals"
              }
           ],
           "price": 1034.99,              
           "status": 1,
           "description": null,               
        }

而且我只想在category_path字段中搜索确切的文本[“ Camcorders”]。 我做了一些匹配查询,但是它搜索了所有以“ Camcorders”作为文本一部分的产品。 有人可以帮我解决这个问题吗?

谢谢

要在嵌套字段中搜索,请使用以下查询

 {
  "query": {
    "term": {
       "category_path.name": {
          "value": "b1"
       }
    }
  }
}

希望能帮助到你..!

您可以使用not_analyzed分析器再添加一个嵌套字段raw_namenot_analyzed匹配。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM