mydeman的学习日志

知行合一

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();
    }
阅读更多

扫码向博主提问

去开通我的Chat快问

mydeman

博客专家

大道至简,量化之道
  • 擅长领域:
  • 架构设计
  • Quants
版权声明:原创文章,欢迎转载,转载请注明出处和原文链接 https://blog.csdn.net/mydeman/article/details/57405971
个人分类: Java 架构设计 学习
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭