elasticsearch - 如何使用模糊性和通配符查询来查询elasticsearch嵌套对象

标签 elasticsearch elasticsearch-nested

{  
   "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 应用程序编写查询。

最佳答案

你可以试试这个。

  {
    "query": {
      "nested": {
        "path": "comments",
        "query": {
          "bool": {
            "should": [
              {
                "wildcard": {
                  "comments.author": "real*"
                }
              },            
              {
                "match": {
                  "comments.author": {
                    "query": "reaa",
                    "fuzziness": "AUTO"
                  }
                }
              }
            ]
          }
        }
      }
    }
  }

关于elasticsearch - 如何使用模糊性和通配符查询来查询elasticsearch嵌套对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53665419/

相关文章:

elasticsearch - Elasticsearch query_string按术语搜索复杂关键字

elasticsearch - 在 Elasticsearch 中按分数排序复合聚合结果

elasticsearch - 在Elastic Search中匹配存储的值和查询

elasticsearch - 尝试在Elasticsearch中重命名嵌套对象名称时出错

elasticsearch - 多层嵌套映射和查询上的“Mapping definition has unsupported parameters”错误

elasticsearch - 修改 Nest 和 Elastic Search 的序列化器设置

autocomplete - Elasticsearch:查找子串匹配

ElasticSearch - 每个节点的最佳分片数量

java - elasticsearch 6.3.2 的 NestedSortBuilder 使用示例

elasticsearch - 查询嵌套对象以及查询Elasticsearch