我最近阅读了有关Elasticsearch的信息,并且正在使用Jest与Amazon Elasticsearch Service进行交互。我已经能够利用Jest的文档和索引数据进入ES。
但是,当我尝试使用布尔查询进行查询时,我看到了极高的延迟。我尝试使用POSTMAN执行POST请求,我发现延迟要低得多。
这是示例:
开玩笑查询:给定键,值:返回对象列表。
客户JestClient:
String query = "{\n" +
" \"query\" : \n" +
" {\"bool\": \n" +
" { \"must\": \n" +
" [\n" +
" {\"match\": \n" +
" {\"" + key +"\" : \"" + value + "\"}\n" +
" }\n" +
" ]\n" +
" }\n" +
" }\n" +
"}";
long startTime, endTime;
Search search = new Search.Builder(query)
// multiple index or types can be added.
.addIndex(indexName)
.addType(typeName)
.build();
endTime = System.currentTimeMillis();
System.out.println("SearchBuilder: " + (endTime - startTime));
startTime = endTime;
JestResult result = client.execute(search);
endTime = System.currentTimeMillis();
System.out.println("ClientExecute: " + (endTime - startTime));
return result.getSourceAsObjectList(<Object>.class);
输出:SearchBuilder:12 ClientExecute:1193
另一方面,使用POSTMAN:我的主体具有POST请求:
{
"query" : {"bool": { "must": [{"match": {key : value}}]}}
}
这是在以下位置执行的:es.ap-southeast-1.es.amazonaws.com/index/_search输出:
“ took”:1,“ timed_out”:false,“ _shards”:{“ total”:10,“ successful”:10,“ failed”:0},
我也尝试使用Searchsourcebuilder。但无济于事。我在使用正确的API吗?
这条线
"took": 1, "timed_out": false, "_shards": { "total": 10, "successful": 10, "failed": 0 }
告诉您实际的ES引擎运行查询所花的时间,但不包括通过互联网发送查询或将结果返回给您时的任何延迟。在您的JestClient示例中,实际上是包含了这一时间,因此,完全有可能在您的JestClient示例以相同的速度执行时,时间差仅与传输和接收数据所花费的时间有关。
我对Jest不太熟悉,但是我在C#中使用过Nest(我认为几乎相同),并且在结果中,您应该能够在返回对象中获得相同的“ took”,“ timed_out”统计信息。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句