我使用的是ES 2.3,现在将其升级到ES 7.4。数据是通过自动测试生成的,因此始终为32个文档。
我在使用ES 2.3进行全部查询时发现,我得到了全部32个文档。
结果中可以找到文档,例如data.id: 5dba917f61b48a327c948557
。
我可以通过data.id
查询它,也可以找到文档。
但是,如果我使用ES 7做同样的事情,我CAN NOT
用data.id:5dba917f61b48a327c948557
查找文档
在查询所有例如。 http://localhost:9200/test-auditing-2019-10/_search?pretty=true结果。
{
"took" : 16,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 32,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "test-auditing-2019-10",
"_type" : "_doc",
"_id" : "J0LIIG4Bw-26hPm9OiXO",
...
查询http://localhost:9200/test-auditing-2019-10/_search?q=data.id:5dba917f61b48a327c948557&pretty=true时,我确实得到了文档。
...
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 2.3795462,
"hits" : [
{
"_index" : "test-auditing-2019-10",
"_type" : "_doc",
"_id" : "RELIIG4Bw-26hPm9WyUP",
...
怎么了?这是预期的吗?非常感谢。
最佳答案
ElasticSearch 2.3太旧,可能会返回所有匹配的文档。我没有这个版本,也无法复制。
但是,即使查询与所有文档匹配,现代的ElasticSearch默认情况下也仅返回10个匹配的文档。为了获得更多匹配的文档,可以使用from
和size
进行分页:
获取前32个文档:
http://localhost:9200/test-auditing-2019-10/_search?from=0&size=32&pretty=true
获取接下来的32个文档:
http://localhost:9200/test-auditing-2019-10/_search?from=32&size=32&pretty=true
关于elasticsearch - 查询elasticsearch可以通过id获取文档,但无法在全部查询中找到它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58653113/