Default index analyzer in elasticsearch

后端 未结 2 340
离开以前
离开以前 2020-12-31 02:58

I am facing a problem with elasticsearch where I dont want my indexed term to be analyzed. But the elasticsearch has some default setting which is tokenizing it on space. T

相关标签:
2条回答
  • 2020-12-31 03:28

    add index.analysis.analyzer.default.type: keyword in your elasticsearch.yml.

    0 讨论(0)
  • 2020-12-31 03:38

    I'd use dynamic templates - it should do what you are looking for:

    {
        "testtemplates" : {
            "dynamic_templates" : [
                {
                    "template1" : {
                        "match" : "*",
                        "match_mapping_type" : "string",
                        "mapping" : {
                            "type" : "string",
                            "index" : "not_analyzed"
                        }
                    }
                }
            ]
        }
    }
    

    More on this approach here:

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

    Important: If someone suggest this approach to solve the not_analyzed issue, it will not work! keyword analyzer does some analyzing on the data and convert the data to small letters.

    e.g. Data: ElasticSearchRocks ==> Keyword Analyzer: elasticsearchrocks

    Try it yourself with analyzing query and see it happening.

    curl -XPUT localhost:9200/testindex -d '{
        "index" : {
            "analysis" : {
                "analyzer" : {
                    "default" : {
                        "type" : "keyword"
                    }
                }
           }
        }
    }'
    

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

    0 讨论(0)
提交回复
热议问题