elasticsearch terms 查询不获取所有文档
elasticsearch terms query not fetching all documents
以下是 _msearch
的术语查询。但它现在并没有给出所有 result.As,它只有 return 结果 4161
,即使数据也存在 4402
。
请提出解决方案。
GET _msearch
{ "index": ["index1", "index2", "index3"]}
{"query": {"terms": {"user_id": [4161,4402] } }}
user_id 的类型是 long
您需要增加 size
参数或以不同方式对数据进行排序。默认情况下,搜索查询只会返回 10 个匹配项,并且很可能返回的前 10 个文档都是 user_id: 4161
.
GET _msearch
{ "index": ["index1", "index2", "index3"]}
{"size": 100, "query": {"terms": {"user_id": [4161,4402] } }}
terms
查询是一个 OR 查询,即 terms: [4161,4402]
等同于 term: 4161 OR term: 4402
。
由于您使用的是 _msearch
,另一种方法是为每个索引发送一个查询,因为您将返回更多数据,您可能会幸运地获得两个用户的数据。
GET _msearch
{ "index": "index1"}
{"query": {"terms": {"user_id": [4161,4402] } }}
{ "index": "index2"}
{"query": {"terms": {"user_id": [4161,4402] } }}
{ "index": "index3"}
{"query": {"terms": {"user_id": [4161,4402] } }}
以下是 _msearch
的术语查询。但它现在并没有给出所有 result.As,它只有 return 结果 4161
,即使数据也存在 4402
。
请提出解决方案。
GET _msearch
{ "index": ["index1", "index2", "index3"]}
{"query": {"terms": {"user_id": [4161,4402] } }}
user_id 的类型是 long
您需要增加 size
参数或以不同方式对数据进行排序。默认情况下,搜索查询只会返回 10 个匹配项,并且很可能返回的前 10 个文档都是 user_id: 4161
.
GET _msearch
{ "index": ["index1", "index2", "index3"]}
{"size": 100, "query": {"terms": {"user_id": [4161,4402] } }}
terms
查询是一个 OR 查询,即 terms: [4161,4402]
等同于 term: 4161 OR term: 4402
。
由于您使用的是 _msearch
,另一种方法是为每个索引发送一个查询,因为您将返回更多数据,您可能会幸运地获得两个用户的数据。
GET _msearch
{ "index": "index1"}
{"query": {"terms": {"user_id": [4161,4402] } }}
{ "index": "index2"}
{"query": {"terms": {"user_id": [4161,4402] } }}
{ "index": "index3"}
{"query": {"terms": {"user_id": [4161,4402] } }}