如何在elasticsearch中编写curl模糊搜索查询

问题描述 投票:0回答:1

我已经在ES中创建了记录并且可以看到它:

curl -XGET http://localhost:9200/companies_test/_search -H 'Content-Type: application/json' -d '{
      "query": {
          "match_all": {}
      }
  }'

退货

{
  "took": 38,
  "timed_out": false,
  "_shards": {
    "total": 3,
    "successful": 3,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "companies_test",
        "_type": "_doc",
        "_id": "0",
        "_score": 1,
        "_source": {
          "regionName": "North America",
          "name": "OpenAI",
          "id": "0"
        }
      }
    ]
  }
}

但是当我试图找到它时:

curl -XGET http://localhost:9200/companies_test/_search -H 'Content-Type: application/json' -d '{
      "query": {
          "fuzzy": {
            "name": {
              "value": "OpenAI",
              "fuzziness": "AUTO"
            }
          }
        }
  }'

它什么也不返回:

{
  "took": 3,
  "timed_out": false,
  "_shards": {
    "total": 3,
    "successful": 3,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

我的搜索查询可能不正确。如何修复它? 这个想法是通过特定区域的名称来模糊搜索公司,并且也不使用区域过滤器。

elasticsearch
1个回答
0
投票

您的分析器将“OpenAI”术语转换为“openai”术语

发送此类查询

GET /fuzzy_queries/_search?filter_path=hits.hits
{
  "query": {
    "fuzzy": {
      "name": {
        "value": "openai"
      }
    }
  }
}

您会收到回复

{
  "hits" : {
    "hits" : [
      {
        "_index" : "fuzzy_queries",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : 0.2876821,
        "_source" : {
          "regionName" : "North America",
          "name" : "OpenAI",
          "id" : "0"
        }
      }
    ]
  }
}

你的问题很简单。请阅读 Elasticsearch 中的文本分析来加深知识

© www.soinside.com 2019 - 2024. All rights reserved.