Elasticsearch上手 - 遇到的问题

TooManyClauses问题

问题描述

在搜索时,遇到了下面的Response:

"caused_by":{"type":"too_many_clauses","reason":"maxClauseCount is set to 1024"}}}],"caused_by":{"type":"query_shard_exception","reason":"failed to create query:

原因

查询中需要对某个字段做terms搜索,传入的候选条件过多。错误代码是:

JSONObject joQuery = query(
                    bool(
                            must(
                                    term("user", userId),
                                    terms("keys", keyList))));

解决办法

将must替换为filte即可:

JSONObject joQuery = query(
                    bool(
                            filter(
                                    term("user", userId),
                                    terms("keys", keyList))));

启动的配置问题

切换了新的服务器,在启动elasticsearch时,看到了下面的提示信息:

max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

这个在文档里给了很详细的说明:
https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/file-descriptors.html

搜索时超时

使用Java RestClient搜索时,出现了超时的问题:

java.io.IOException: listener timeout after waiting for [30000] ms
    at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:617) ~[rest-5.2.0.jar:5.2.0]
    at org.elasticsearch.client.RestClient.performRequest(RestClient.java:212) ~[rest-5.2.0.jar:5.2.0]
    at org.elasticsearch.client.RestClient.performRequest(RestClient.java:184) ~[rest-5.2.0.jar:5.2.0]

在创建RestClient时,设置超过时长:

private RestClient getClient(){
        return RestClient.builder(
                new HttpHost(systemConfig.elasticsearchHost, Integer.parseInt(systemConfig.elasticsearchHttpPort), "http"))
                .setMaxRetryTimeoutMillis(5 * 60 * 1000) //超时时间设为5分钟
                .build();
    }

猜你喜欢

转载自blog.csdn.net/mydeman/article/details/57405971