弹性搜索:搜索带通配符的整数 [英] Elastic search : Searching for integers with wildcards

查看:215
本文介绍了弹性搜索:搜索带通配符的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用轮胎客户端进行弹性搜索。假设我有一个字段,在我的弹性搜索映射中被索引为long类型的字段。
我正在尝试这样做:

  search.query {| query | query.string30 *,:fields => ['id']} 

这里'id'是我正在谈论的长字段。但是,由于我在查询中指定了字段,所以通配符不起作用,最终得到完全匹配的唯一结果。



但做同样的事情与_all搜索作为字段类型无关紧要。我想要这个通配符搜索工作,同时还在该特定字段中搜索搜索关键字。有没有办法这样做,而不改变我的映射?

解决方案

感谢@alex在该脚本提示。最后我找到了一些有用的东西。噢!



所以我最后这样做(简要地说):

  search.query do | query | 
query.filtered do | f |
f.filter:script,{
:script => doc ['id']。value.toString()〜='^ 30 [0-9] * $'
}
end
end

希望有帮助。


I am currently using the tire client for elastic search. Lets say I have a field which is indexed as a field of type long in my elastic search mapping. I am trying to achieve something like this:

search.query {|query| query.string "30*", :fields => ['id']}

Here 'id' is the long field about which I was talking about. But since I specify the fields in the query, the wildcard doesn't work and I end up getting the exact match as the only result.

But doing the same thing works with the _all search as the field type doesn't matter. I want this wildcard search to work while also searching for the search key in that particular field. Is there any way to do this without changing my mapping?

解决方案

Thanks to @alex on that scripting tip. Finally I found something which worked. Phew!

So I ended up doing this(briefly):

search.query do |query|
  query.filtered do |f|
      f.filter :script, { 
    :script => "doc['id'].value.toString() ~= '^30[0-9]*$'"
      }
  end
end

Hope it helps.

这篇关于弹性搜索:搜索带通配符的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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