首页 > 解决方案 > 如何在完整的字典中搜索

问题描述

{'name':'abc','description':{'value':'abc','test':124}}

我在上面有一个 DSL 查询。我的关键“描述”是一组字典,以下查询是否正确

{
   "from":0,
   "size":1000,
   "query":{
      "bool":{
         "must":{
            "query_string":{
               "query":"Pencil",
               "fields":[
                  "name^8",
                  "description^2"
               ]
            }
         }
      }
   }
}

如果我想在字典上搜索特定关键字,那么我可以这样做description.value.keyword

标签: elasticsearchdsl

解决方案


如果未提供任何字段,则 multi_match 查询默认为 index.query.default_field 索引设置,而后者又默认为 *。它提取映射中符合术语查询的所有字段并过滤元数据字段。然后组合所有提取的字段以构建查询。

如果要搜索and字段中的所有属性,可以使用多匹配查询namedescription

添加具有索引数据、映射、搜索查询和搜索结果的工作示例

指数数据:

{
  "name": "abc",
  "description": {
    "value": "abc",
    "test": 124
  }
}
{
  "name": "John",
  "description": {
    "value": "abc",
    "test": 124
  }
}

搜索查询:

{
  "query": {
    "multi_match" : {
      "query":    "abc"
    }
  }
}

搜索结果:

"hits": [
      {
        "_index": "65824093",
        "_type": "_doc",
        "_id": "1",
        "_score": 0.6931471,
        "_source": {
          "name": "abc",
          "description": {
            "value": "abc",
            "test": 124
          }
        }
      },
      {
        "_index": "65824093",
        "_type": "_doc",
        "_id": "2",
        "_score": 0.18232156,
        "_source": {
          "name": "John",
          "description": {
            "value": "abc",
            "test": 124
          }
        }
      }
    ]

如果您想知道所有字段中哪个字段匹配,那么您可以使用突出显示


推荐阅读