轮胎术语过滤器不工作 [英] tire terms filter not working

查看:117
本文介绍了轮胎术语过滤器不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用轮胎/弹性搜索来实现像范围功能。为什么这不工作,即使我有状态为Test1或Test2的条目?结果总是为空。

  collection = @ model.search(:page => page,:per_page => per_page )do | s | 
s.query {all}
s.filter:terms,:status => [Test1,Test2]
s.sort {by:#{column},#{direction}}
end
/ pre>

该方法工作正常,没有过滤器。过滤方法有问题吗?我检查了轮胎doku ....它应该工作。



谢谢! :)

解决方案

您的问题最可能是由于使用状态的默认映射字段,它将标记它 - 小写,分为单词等。



比较这两个:

  http:// localhost:9200 / myindex / _analyze?text = Text1& analyzer = standard 

http:// localhost:9200 / myindex / _analyze?text = Text1& analyzer = keyword

您的案例中的解决方案是使用<$在您的映射中,c $ c>关键字分析器(或将字段设置为 not_analyzed )。当该字段不是枚举类型的数据时,您可以使用多字段功能。



一个工作的Ruby版本将如下所示:

  require'tire'

Tire.index('myindex')do
delete
创建映射:{
文档:{
属性:{
status:{type:'string',analyzer:'keyword'}
}
}
}

存储状态:'Test1'
商店状态:'Test2'

刷新
结束

search = Tire.search'myindex'做
查询$ $ $ $ b过滤do
查询{all}
过滤器:条件,状态:['Test1']
end
end
end

puts search.results.to_a.inspect






注意:很少有可能 - 这个案例是一个例外 - 提供合理的建议没有提供索引映射,示例数据等。


I'm trying to achieve a "scope-like" function with tire/elasticsearch. Why is this not working, even when i have entries with status "Test1" or "Test2"? The results are always empty.

  collection = @model.search(:page => page, :per_page => per_page) do |s|
    s.query {all}
    s.filter :terms, :status => ["Test1", "Test2"]
    s.sort {by :"#{column}", "#{direction}"}
  end 

The method works fine without the filter. Is something wrong with the filter method?! I've checked the tire doku....it should work.

Thanks! :)

解决方案

Your issue is most probably being caused by using the default mappings for the status field, which would tokenize it -- downcase, split into words, etc.

Compare these two:

http://localhost:9200/myindex/_analyze?text=Text1&analyzer=standard

http://localhost:9200/myindex/_analyze?text=Text1&analyzer=keyword

The solution in your case is to use the keyword analyzer (or set the field to not_analyzed) in your mapping. When the field would not be an "enum" type of data, you could use the multi-field feature.

A working Ruby version would look like this:

require 'tire'

Tire.index('myindex') do
  delete
  create mappings: {
    document: {
      properties: {
        status: { type: 'string', analyzer: 'keyword' }
      }
    }
  }

  store status: 'Test1'
  store status: 'Test2'

  refresh
end

search = Tire.search 'myindex' do
  query do
    filtered do
      query { all }
      filter :terms, status: ['Test1']
    end
  end
end

puts search.results.to_a.inspect


Note: It's rarely possible -- this case being an exception -- to offer reasonable advice when no index mappings, example data, etc. are provided.

这篇关于轮胎术语过滤器不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆