1
{  
   "took":1,
   "timed_out":false,
   "_shards":{  
      "total":5,
      "successful":5,
      "skipped":0,
      "failed":0
   },
   "hits":{  
      "total":1,
      "max_score":1,
      "hits":[  
         {  
            "_index":"event_11",
            "_type":"_doc",
            "_id":"1",
            "_score":1,
            "_source":{  
               "title":"Event One",
               "comments":{  
                  "author":"Alvin",
                  "author_id":1
               }
            },
            "inner_hits":{  
               "comments":{  
                  "hits":{  
                     "total":1,
                     "max_score":1,
                     "hits":[  
                        {  
                           "_index":"event_11",
                           "_type":"_doc",
                           "_id":"1",
                           "_nested":{  
                              "field":"comments",
                              "offset":0
                           },
                           "_score":1,
                           "_source":{  
                              "author":"Alvin",
                              "author_id":1
                           }
                        }
                     ]
                  }
               }
            }
         }
      ]
   }
}

我正在尝试使用以下通配符查询来查询上述数据:

GET event_11/_search
{
  "query": {
    "nested": {
      "path": "comments",
        "query": {
          "wildcard": {
              "comments.author": "Al*"
          } 
        }
    }
  }
}

上面的查询给出了空的结果集。有人可以帮助我使用通配符和模糊性修复搜索查询吗?我正在使用 ElasticSearch 6 和 Kibana 来创建我的查询。PHP SDK 用于编写来自 PHP 应用程序的查询。

4

1 回答 1

3

You can try this.

  {
    "query": {
      "nested": {
        "path": "comments",
        "query": {
          "bool": {
            "should": [
              {
                "wildcard": {
                  "comments.author": "real*"
                }
              },            
              {
                "match": {
                  "comments.author": {
                    "query": "reaa",
                    "fuzziness": "AUTO"
                  }
                }
              }
            ]
          }
        }
      }
    }
  }
于 2018-12-07T12:48:44.207 回答