Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

Elasticsearch search API does not return results when called with document type

I am trying to retrieve data from ES using the search API. The name of the index is index_certificate and the document type is doc_certificate.

Below API call works fine and returns results.

curl -X POST "http://elasticsearch:9200/index_certificate/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "district_id": {
              "query": "10"
            }
          }
        }
      ]
    }
  }
}'

But if I add the document type to the url without changing any other thing as below, it returns an empty result array. (Does not throw any errors)

curl -X POST "http://elasticsearch:9200/index_certificate/doc_certificate/_search?pretty" -H 'Content-Type: application/json' -d' { "query": { "bool": { "must": [ { "match": { "district_id": { "query": "10" } } } ] } } }'

I am not the one who did setup the node. Also this is not a production node. I am not sure whether this can be due to a read/write permission issue related to the document. I appreciate if someone can help me to solve this. Thank you.

question from:https://stackoverflow.com/questions/65941815/elasticsearch-search-api-does-not-return-results-when-called-with-document-type

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As you can see the _type of your documents is _doc and not doc_certificate

So the following would work:

curl -X POST "http://elasticsearch:9200/index_certificate/_doc/_search?pretty" -H 'Content-Type: application/json' -d' { "query": { "bool": { "must": [ { "match": { "district_id": { "query": "10" } } } ] } } }'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...