ElasticSearch n-gram tokenfilter不能找到部分单词

9

我一直在为我的新项目玩弄ElasticSearch。我已将默认分析器设置为使用ngram令牌过滤器。这是我的elasticsearch.yml文件:

index:
analysis:
    analyzer:
        default_index:
            tokenizer: standard
            filter: [standard, stop, mynGram]
        default_search:
            tokenizer: standard
            filter: [standard, stop]

    filter:
        mynGram:
            type: nGram
            min_gram: 1
            max_gram: 10

我创建了一个新的索引,并向其中添加了以下文档:
$ curl -XPUT http://localhost:9200/test/newtype/3 -d '{"text": "one two three four five six"}'
{"ok":true,"_index":"test","_type":"newtype","_id":"3"}

然而,当我使用查询text:hreetext:ive或任何其他部分术语进行搜索时,ElasticSearch不会返回此文档。只有在搜索精确词项(如text:two)时,它才返回文档。
我还尝试更改配置文件,使default_search也使用ngram令牌过滤器,但结果仍然相同。我在这里做错了什么,如何纠正?

嘿,布莱恩,请问你能否发布已更正的配置文件以便完整吗?我也遇到了同样的问题。 - Rich
2个回答

10

我不确定默认的_default设置,但应用指定了index_analyzer和search_analyzer的映射可以起效:

curl -XDELETE localhost:9200/twitter
curl -XPOST localhost:9200/twitter -d '
{"index": 
  { "number_of_shards": 1,
    "analysis": {
       "filter": {
                  "mynGram" : {"type": "nGram", "min_gram": 2, "max_gram": 10}
                 },
       "analyzer": { "a1" : {
                    "type":"custom",
                    "tokenizer": "standard",
                    "filter": ["lowercase", "mynGram"]
                    }
                  } 
     }
  }
}
}'

curl -XPUT localhost:9200/twitter/tweet/_mapping -d '{
    "tweet" : {
        "index_analyzer" : "a1",
        "search_analyzer" : "standard", 
        "date_formats" : ["yyyy-MM-dd", "dd-MM-yyyy"],
        "properties" : {
            "user": {"type":"string", "analyzer":"standard"},
            "message" : {"type" : "string" }
        }
    }}'

curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{
    "user" : "kimchy",
    "post_date" : "2009-11-15T14:12:12",
    "message" : "trying out Elastic Search"
}'

curl -XGET localhost:9200/twitter/_search?q=ear
curl -XGET localhost:9200/twitter/_search?q=sea

curl -XGET localhost:9200/twitter/_mapping

1
我其实已经放弃了 Elastic Search,现在已经设置好并完美地运行 Solr。等我有时间了,我会尝试这个解决方案,看看效果如何。 - asleepysamurai
1
我已经提交了对这个答案的编辑,因为它是误导性的,并试图将映射应用于整个索引,而需要将其应用于类型。 - Travis
curl -XPUT localhost:9200/twitter/_mapping -d '{ 应该改为 curl -XPUT localhost:9200/twitter/tweet/_mapping -d '{ - rado

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接