Elasticsearch上手 - 遇到的问题

标签: elasticsearchjavapython搜索性能
2041人阅读 评论(0) 收藏 举报
分类:

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();
    }
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1132869次
    • 积分:12363
    • 等级:
    • 排名:第1284名
    • 原创:174篇
    • 转载:6篇
    • 译文:34篇
    • 评论:398条
    博客专栏
    最新评论
    独乐乐不如众乐乐