Elasticsearch 搜索 API 未返回所有结果

Elasticsearch search API not returning all the results

我有三个索引,它们都共享一个特定的键值对。当我使用请求正文

使用 api“http://localhost:9200/_search”进行全面搜索时
{"query":{
    "query_string":
    {
        "query":"city*"

        }
    }
}

它只返回两个索引的结果。我尝试通过更改 url 以仅在丢失的索引“http://localhost:9200/index_name/_search”中搜索来使用相同的请求正文,这很有效。我在这里遗漏了什么吗?

插入所有三个索引的代码遵循相同的过程,我使用 elasticsearch-py 来摄取数据。

我正在使用 GET HTTP 方法并且还尝试了 POST HTTP 方法。两者returns相同的结果。 Elasticsearch 版本为 7.6.0.

特定索引搜索结果如下

{
    "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" 
                }
            }
        ]
    }
}

原因可能是您没有在查询中提供大小参数。默认情况下,这会将结果计数限制为 10。在所有结果中,前 10 名可能来自两个索引,即使匹配也存在于第三个索引中。这反过来给人的感觉是没有返回第三个索引的结果。

尝试添加 size 参数。

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

您可以通过响应中的 total 键计算出与查询匹配的文档数量

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