ElasticSearch 映射不起作用

发布于 2024-11-11 18:54:17 字数 975 浏览 0 评论 0原文

我正在尝试为各个字段使用不同的分析器设置 ElasticSearch 索引。但是,我似乎找不到设置特定领域分析器的方法;这是我创建(测试)索引的方法:

curl -XPOST localhost:9200/twitter
curl -XPUT 'http://localhost:9200/twitter/tweet/_mapping' -d '
{
    "tweet" : {
        "properties" : {
            "message" : {
                "type" : "string",
                "search_analyzer" : "snowball", 
                "index_analyzer" : "snowball"
            }
        }
    }
}'

如果我正确阅读了文档,那么这应该创建类型为“tweet”的索引“twitter”,并且应该通过雪球词干分析器来分析“message”字段的内容。 为了测试这一点,我尝试了以下查询:

curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{
    "message" : "Look, a fighting War-Unicorn!"
}'
curl -XGET localhost:9200/twitter/_search?q=fight

如果我没记错的话,那么这应该返回一个命中,因为战斗是战斗的主干;问题是,事实并非如此,我的点击率为零。看起来好像 ElasticSearch 完全忽略了映射(即使 ElasticSearch 接受所有这些查询,因为我对每个查询都得到“ok”返回。)

我已经尝试用雪球分析器替换默认分析器,然后它就可以工作了;问题是,我完全需要有特定领域的分析仪,所以这对我没有帮助。我还尝试了不同的分析器以及将“index”设置为“no”等操作,但无济于事。

我做错了什么?

I'm trying to set up an ElasticSearch index with different analyzers for the individual fields. However, I can't seem to find a way to set field-specific analyzers; here's how I create my (test) index:

curl -XPOST localhost:9200/twitter
curl -XPUT 'http://localhost:9200/twitter/tweet/_mapping' -d '
{
    "tweet" : {
        "properties" : {
            "message" : {
                "type" : "string",
                "search_analyzer" : "snowball", 
                "index_analyzer" : "snowball"
            }
        }
    }
}'

If I read the documentation correctly, then this should create the index 'twitter' with the type 'tweet', and content for the 'message' field should be analyzed through the snowball stemming analyzer.
To test for this, I tried the following queries:

curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{
    "message" : "Look, a fighting War-Unicorn!"
}'
curl -XGET localhost:9200/twitter/_search?q=fight

If I'm not mistaken, then this should return a hit, as fight is the stem for fighting; the problem is, it doesn't, I'm getting zero hits. It appears as if ElasticSearch ignores the mapping entirely (even though ElasticSearch accepts all of these queries, as I get 'ok' back for each of them.)

I've already tried replacing the default analyzer with a snowball analyzer, and then it works; thing is, I totally need to have field-specific analyzers, so this isn't going to help me. I also tried different analyzers and things like setting "index" to "no", but to no avail.

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情独悲 2024-11-18 18:54:17

要使用特定于字段的分析器,您需要在查询中指定该字段。否则,使用默认分析器。尝试

curl -XGET 'localhost:9200/twitter/_search?q=message:fight'

curl -XGET 'localhost:9200/twitter/_search?df=message&q=looking'

To use a field-specific analyzer you need to specify this field in the query. Otherwise, default analyzer is used. Try

curl -XGET 'localhost:9200/twitter/_search?q=message:fight'

or

curl -XGET 'localhost:9200/twitter/_search?df=message&q=looking'
蒗幽 2024-11-18 18:54:17

我建议您使用 https://github.com/lmenezes/elasticsearch-kopf 可以测试所有分析器并从另一个索引复制映射并监视您的索引...
http://www.elasticsearch.org/guide/en /elasticsearch/client/community/current/health.html

I recommend to you use https://github.com/lmenezes/elasticsearch-kopf can test all analyzers and copy mapp from another index and monitor your indexes...
http://www.elasticsearch.org/guide/en/elasticsearch/client/community/current/health.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文