Elasticsearch5常见问题汇总

来源:互联网 发布:23号端口 编辑:程序博客网 时间:2024/06/07 17:15
Elasticsearch5常见问题汇总

1. 跨域支持
编辑elasticsearch.yml文件,增加以下配置:
http.cors.enabled: true
http.cors.allow-origin: "*"

2. 最大布尔查询数量
编辑elasticsearch.yml文件,增加以下配置:
indices.query.bool.max_clause_count: 10240

3. 为索引和检索指定不同的分词器
{    "mappings": {        "default": {            "properties": {                "keyword": {                    "type": "text",                    "analyzer": "索引分词器",                    "search_analyzer": "检索分词器",                    "search_quote_analyzer": "引号检索分词器"                }            }        }    }}

4. 在ActionPlugin插件中处理JSON
4.1 获取POST请求内容
if(RestActions.hasBodyContent(request)) {
BytesReference content = RestActions.getRestContent(request);
Tuple<XContentType, Map<String, Object>> tuple = XContentHelper.convertToMap(content, true);
if(XContentType.JSON == tuple.v1()) instance.params = tuple.v2();
}
4.2 将JSON字符串转换为Map对象
XContentFactory.xContent(XContentType.JSON).createParser(json).mapOrdered();
4.3 将Map对象转换为JSON字符串
XContentFactory.jsonBuilder().map((Map<String, ?>) object).string();
4.4 关于URL中请求字符串的处理特性
QueryStringPHPJavaElastcisearcha=1字符串数组字符串a=1&a=2最后一个字符串数组最后一个字符串a[]=1&a[]=2数组Key=a数组Key=a[]最后一个字符串Key=a[]a[0]=1&a[1]=2数组多个数组多个字符串a.k1=1&a.k2=2多个字符串多个数组多个字符串
Elasticsearch内部通信和对外服务均采用Netty框架,支持JSON和YAML等多种数据格式,基于URI注册RestHandler,不建议采用请求字符串的方式传递参数。

5. 复杂查询
多看官方文档,绝大部分的需求都能在文档中找到答案,通过Aggregations组合可实现不同的功能。

0 0
原创粉丝点击