[英]Elasticsearch long query fails to search
Example of my query: 我的查询示例:
"query" : {
"bool" : {
"must" : [
{ "terms" : { "group_id" : ["1","2","3","4","5","6","7","8"]} }
]
}
}
I json encode it and send with curl 我json编码并卷曲发送
http://localhost:9200/document/_search?source=JSON_ENCODED_QUERY http:// localhost:9200 / document / _search?source = JSON_ENCODED_QUERY
The above works just fine. 以上工作正常。
But I get the problem if I add few hundred of group IDs to the query. 但是,如果将数百个组ID添加到查询中,则会出现问题。
Server response: 服务器响应:
curl: (52) Empty reply from server
How can I solve my problem? 我该如何解决我的问题?
One thing to try is terms lookup . 可以尝试的一件事是术语查找 。 It lets you specify another index as the source of the terms for which you are searching.
它使您可以指定另一个索引作为要搜索的术语的来源。 Here is a simple example.
这是一个简单的例子。
First, I create an index with two types. 首先,我创建具有两种类型的索引。
"doc"
will be the documents we are searching for, and "query_terms"
will be used to store the terms we want to query against. "doc"
将是我们要搜索的文档, "query_terms"
将用于存储要查询的术语。 Here is the index definition: 这是索引定义:
PUT /test_index
{
"mappings": {
"doc": {
"properties": {
"group_id": { "type": "integer" },
"text": { "type": "string" }
}
},
"query_terms": {
"properties": {
"values": { "type": "string" }
}
}
}
}
Then I add some docs: 然后我添加一些文档:
POST /test_index/doc/_bulk
{"index":{}}
{"group_id":1,"text":"Lorem ipsum"}
{"index":{}}
{"group_id":2,"text":"dolor sit amet"}
{"index":{}}
{"group_id":3,"text":"consectetur adipiscing elit"}
{"index":{}}
{"group_id":4,"text":"Pellentesque eu nisi"}
{"index":{}}
{"group_id":5,"text":"sit amet."}
{"index":{}}
{"group_id":6,"text":"velit pellentesque"}
{"index":{}}
{"group_id":7,"text":"ornare eleifend a leo"}
{"index":{}}
{"group_id":8,"text":"Integer in aliquam turpis"}
{"index":{}}
{"group_id":9,"text":"Pellentesque sed"}
{"index":{}}
{"group_id":10,"text":"quam sit amet"}
Now I'll add a "query_terms"
document with a PUT
: 现在,我将添加一个带有
PUT
的"query_terms"
文档:
PUT /test_index/query_terms/1
{
"values": [2,4,6,8]
}
And I can use it to query the documents: 我可以用它来查询文档:
POST /test_index/doc/_search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"terms": {
"group_id": {
"index": "test_index",
"type": "query_terms",
"id": "1",
"path": "values"
}
}
}
}
}
}
...
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 1,
"hits": [
{
"_index": "test_index",
"_type": "doc",
"_id": "d07TqRjjRvWW9MJOH1l13Q",
"_score": 1,
"_source": {
"group_id": 2,
"text": "dolor sit amet"
}
},
{
"_index": "test_index",
"_type": "doc",
"_id": "Qqy1idktQBqoKTR279DMXQ",
"_score": 1,
"_source": {
"group_id": 4,
"text": "Pellentesque eu nisi"
}
},
{
"_index": "test_index",
"_type": "doc",
"_id": "RoFzGAOhQxmetvbh8-weew",
"_score": 1,
"_source": {
"group_id": 6,
"text": "velit pellentesque"
}
},
{
"_index": "test_index",
"_type": "doc",
"_id": "IRH0qS9QQmWJEmgGMIr2SQ",
"_score": 1,
"_source": {
"group_id": 8,
"text": "Integer in aliquam turpis"
}
}
]
}
}
For this example, a simpler approach would have worked just fine, but this approach should scale up to very long lists of terms. 对于此示例,一种更简单的方法会很好用,但是此方法应扩展到非常长的术语列表。
Here is the code I used: 这是我使用的代码:
http://sense.qbox.io/gist/cbaab881c5fa5fd7fd6dfc819e2bea82d09495e6 http://sense.qbox.io/gist/cbaab881c5fa5fd7fd6dfc819e2bea82d09495e6
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.