【问题标题】:How to search exact text in nested document in elasticsearch如何在弹性搜索中搜索嵌套文档中的确切文本
【发布时间】:2014-05-29 18:25:27
【问题描述】:

我有一个这样的索引,

        "_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"]。 我做了一些匹配查询,但它搜索所有文本中包含“摄像机”的产品。谁能帮我解决这个问题。

谢谢

【问题讨论】:

标签: elasticsearch


【解决方案1】:

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

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

希望对您有所帮助..!

【讨论】:

  • 如果有效..接受答案并帮助其他人找到答案...!
【解决方案2】:

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

【讨论】:

  • 谢谢。是的,没有地图 not_analyzed 它不会得到结果
猜你喜欢
  • 2015-06-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-12
  • 1970-01-01
  • 2015-12-18
相关资源
最近更新 更多