简体   繁体   中英

Elasticsearch search API not returning all the results

I have three indexes, all three of them share a particular key-value pair. When I do a blanket search with the api " http://localhost:9200/_search " using the request body

{"query":{
    "query_string":
    {
        "query":"city*"

        }
    }
}

It is only returning results from two of the indexes. I tried using the same request body by altering the url to search only in that missed index " http://localhost:9200/index_name/_search " and that's working. Am I missing anything here?

The code for inserting all three indexes follow the same procedure and I used elasticsearch-py to ingest the data.

I'm using the GET HTTP method and also tried the POST HTTP method. Both returns the same results. Elasticsearch version is 7.6.0.

Results for specific index search is like the one below

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 1,
            "relation": "eq"
        },
        "max_score": 1.0,
        "hits": [
            {
                "_index": "index_name",
                "_type": "meta",
                "_id": "LMRqDnIBh5wU6Ax_YsOD",
                "_score": 1.0,
                "_source": {
                    "table_schema": "test_table",
                    "table_name": "citymaster_old" 
                }
            }
        ]
    }
}

The reason might be that you haven't provided the size parameter in the query. This limits the result count to 10 by default. Out of all the results the top 10 might be from the two index even thought the match is present in third index as well. This in turn giving the perception that result from third index are not being returned.

Try adding size parameter.

{
  "query": {
    "query_string": {
      "query": "city*"
    }
  },
  "size": 20
}

You can figure out the number of documents that matched the query by the total key in response

"total": {
            "value": 1,
            "relation": "eq"
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM