1

我在使用轮胎和关键字类型分析器设置弹性搜索时遇到问题。

我的映射定义是这样的:

Tire.index 'my_index' do
    delete

    create :mappings => {

        "my_type" => {
          :properties => {
            :id => { :type => 'string', :index => 'not_analyzed', :include_in_all => false },
            :user_id => { :type => 'string', :index => 'not_analyzed'},
            :team_id => { :type => 'string', :index => 'not_analyzed', :analyzer => 'keyword'},
            "_timestamp" => { :enabled => true,  :path => "created_on"}
          }
        }
}
end

我添加了一些数据 team:id: "blah-blih-bloh"

如果我搜索

curl -XGET 'http://localhost:9200/my_index/my_type/_search?q=team_id:blah'

如果分析器是“关键字”,我也可以找到我插入的数据。

我想用用户构面对 team_id 的数据进行分组,但鉴于关键字分析器似乎没有按预期工作,我无法检索到好的结果,因为它标记了“team_id”字段。如果我有两个用户的 team_id = "blah-blih-bloh",我会得到 2 个结果为 "blah",2 个为 "blih",2 个为 "bloh",2 个为 "blah-blih-bloh"。

我错过了什么吗?

编辑:我解决了这个问题,它与轮胎有关。如果我这样做了,轮胎没有正确地破坏和重新创建索引

curl -XDELETE

在 ElasticSearch 的索引上,然后我执行与以前相同的代码,正确创建了映射,插入了数据,一切都按预期工作。

4

0 回答 0