gpt4 book ai didi

curl - Elasticsearch长查询无法搜索

转载 作者:行者123 更新时间:2023-12-03 01:05:51 25 4
gpt4 key购买 nike

我的查询示例:

"query" : {
"bool" : {
"must" : [
{ "terms" : { "group_id" : ["1","2","3","4","5","6","7","8"]} }
]
}
}

我对它进行json编码并发送curl

http://localhost:9200/document/_search?source=JSON_ENCODED_QUERY

以上工作正常。

但是,如果将数百个组ID添加到查询中,则会出现问题。

服务器响应:
curl: (52) Empty reply from server

我该如何解决我的问题?

最佳答案

可以尝试的一件事是terms lookup。它使您可以指定另一个索引作为要搜索的术语的来源。这是一个简单的例子。

首先,我创建具有两种类型的索引。 "doc"将是我们要搜索的文档,并且"query_terms"将用于存储我们要查询的术语。这是索引定义:

PUT /test_index
{
"mappings": {
"doc": {
"properties": {
"group_id": { "type": "integer" },
"text": { "type": "string" }
}
},
"query_terms": {
"properties": {
"values": { "type": "string" }
}
}
}
}

然后我添加一些文档:
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"}

现在,我将添加一个带有 "query_terms"PUT文档:
PUT /test_index/query_terms/1
{
"values": [2,4,6,8]
}

我可以用它来查询文档:
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"
}
}
]
}
}

对于此示例,一种更简单的方法会很好用,但是该方法应扩展到非常长的术语列表。

这是我使用的代码:

http://sense.qbox.io/gist/cbaab881c5fa5fd7fd6dfc819e2bea82d09495e6

关于curl - Elasticsearch长查询无法搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29629735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com