弹性搜索中的默认索引分析器

弹性搜索中的默认索引分析器

本文介绍了弹性搜索中的默认索引分析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在面对弹性搜索的问题,我不希望对我的索引项进行分析。但是弹性搜索有一些默认设置,它在空间上标记它。
因此,我的facet查询不返回我想要的结果。

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.Therefore my facet query is not returning the result I want.

我读到索引类型属性中的index:not_analyzed应该可以工作。
但问题是我手头不知道我的文档结构。我将索引随机的MySQL数据库到弹性搜索,而不知道表结构。

I read that "index" : "not_analyzed" in properties of index type should work.But the problem is that I dont know my document structure before hand. I would be indexing random MySQL databases to elasticsearch without knowing the table structure.

我如何设置弹性搜索,默认情况下它使用index :not_analyzed,直到另有要求。
谢谢

How can I setup elasticsearch such that by default it uses "index" : "not_analyzed" until otherwise asked for.Thanks

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

PS: I am using java if I can directly use any API for it I would love it.

推荐答案

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

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"
                    }
                }
            }
        ]
    }
}

这里有更多的方法:

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

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.

例如
数据:ElasticSearchRocks ==>关键字分析器:elasticsearchrocks

自己尝试分析查询并看到它发生。

Try it yourself with analyzing query and see it happening.

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

这篇关于弹性搜索中的默认索引分析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 07:02