Search code examples
elasticsearch

The elasticsearch search query returns an empty result


help me please. I have Elasticsearch 8.11.3. There is an index with the following structure:

"Период": "2023-12-12T21:23:37Z", "БазовыйURL": "api.site.ru:443",

My query search:

POST myindex-alias/_doc/_search?pretty
{"from":0,"size":200,"query":{"bool":{"must":[{"range":{"Период":{"time_zone":"+07:00","gte":"2023-12-01T00:00:00","lte":"2023-12-21T23:59:59"}}}]}},"sort":{"Период":{"order":"asc"}}}

The returned response:

{
  "_index": "myindex-alias",
  "_id": "_search",
  "_version": 27,
  "result": "updated",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 81326,
  "_primary_term": 1
}

Why is there no "hits" section in the response?

The following query: GET myindex-alias/_search?from=0&size=10

returns the result:

{
  "took": 9,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 10000,
      "relation": "gte"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "model_erp_log_exchange_ozon-000001",
        "_id": "d7c428c4-243c-40d4-8019-eb48fa1ec8e2",
        "_score": 1,
        "_source": {
          "Период": "2023-12-12T21:23:37Z",
          "БазовыйURL": "api-seller.ozon.ru:443"
      ...

Solution

  • You're not sending the query to the right endpoint

              remove _doc from here
                       |
                       v
    POST myindex-alias/_search?pretty
    {"from":0,"size":200,"query":{"bool":{"must":[{"range":{"Период":{"time_zone":"+07:00","gte":"2023-12-01T00:00:00","lte":"2023-12-21T23:59:59"}}}]}},"sort":{"Период":{"order":"asc"}}}
    

    Otherwise, you're creating a document with ID _search in your index.

    You can probably delete it now using

    DELETE myindex-alias/_doc/_search