如何在完整词典上搜索

How to search on full dictionary

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

我在上面有一个 DSL 查询。我的key 'description' 是一组字典,下面的查询是否正确

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

如果我想在字典中搜索特定的关键字,那么我可以description.value.keyword

If no fields are provided, the multi_match query defaults to the index.query.default_field index settings, which in turn defaults to *. It extracts all fields in the mapping that are eligible to term queries and filters the metadata fields. All extracted fields are then combined to build a query.

如果要搜索 namedescription 字段中的所有属性,可以使用 multi-match query

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

索引数据:

{
  "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
          }
        }
      }
    ]

如果你想知道所有字段中哪个字段被匹配,那么你可以使用highlighting