elasticsearch中的默认索引分析器

Glo*_*ior 18 elasticsearch

我正面临弹性搜索的问题,我不希望我的索引术语被分析.但是elasticsearch有一些默认设置,可以在空间上对其进行标记.因此我的facet查询不会返回我想要的结果.

我读到"index" : "not_analyzed"在索引类型的属性应该工作.但问题是我手头上不知道我的文档结构.我会在不知道表结构的情况下将随机MySQL数据库索引到elasticsearch.

我如何设置elasticsearch,以便默认情况下使用,"index" : "not_analyzed"直到另外要求.谢谢

PS:我正在使用java,如果我可以直接使用任何API,我会喜欢它.

Joh*_*one 17

我会使用动态模板 - 它应该做你想要的:

{
    "testtemplates" : {
        "dynamic_templates" : [
            {
                "template1" : {
                    "match" : "*",
                    "match_mapping_type" : "string",
                    "mapping" : {
                        "type" : "string",
                        "index" : "not_analyzed"
                    }
                }
            }
        ]
    }
}
Run Code Online (Sandbox Code Playgroud)

有关此方法的更多信息:

https://www.elastic.co/guide/en/elasticsearch/guide/current/custom-dynamic-mapping.html#dynamic-templates

重要提示: 如果有人建议采用这种方法来解决not_analyzed问题,那么它将无效! 关键字分析器对数据进行一些分析并将数据转换为小写字母.

例如 Data: ElasticSearchRocks ==> Keyword Analyzer: elasticsearchrocks

分析查询并亲眼看看它.

curl -XPUT localhost:9200/testindex -d '{
    "index" : {
        "analysis" : {
            "analyzer" : {
                "default" : {
                    "type" : "keyword"
                }
            }
       }
    }
}'
Run Code Online (Sandbox Code Playgroud)

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/analysis-keyword-analyzer.html


Ale*_*yuv 6

加入index.analysis.analyzer.default.type: keyword你的elasticsearch.yml.