Ruby 如何使Searchkick/Elasticsearch where子句不区分大小写?
我正在用Ruby(Ruby 如何使Searchkick/Elasticsearch where子句不区分大小写?,ruby,
elasticsearch,searchkick,Ruby,
elasticsearch,Searchkick,我正在用Ruby(Searchkick)使用ElasticSearch。目前,默认情况下,where过滤器区分大小写 我将ElasticSearch与我的EquityContract模型一起使用,因此一旦我搜索食物,我会得到不同的结果来搜索食物 [21] pry(main)> EquityContract.search('*', {:load=>false, :where=>{:industry=>"FOOD"}, limit:1}) effective_url=
Searchkick
)使用ElasticSearch
。目前,默认情况下,where过滤器区分大小写
我将ElasticSearch与我的EquityContract
模型一起使用,因此一旦我搜索食物
,我会得到不同的结果来搜索食物
[21] pry(main)> EquityContract.search('*', {:load=>false, :where=>{:industry=>"FOOD"}, limit:1})
effective_url=http://127.0.0.1:9200/equity_contracts_development/_search response_code=200 return_code=ok total_time=0.002279
EquityContract Search (5.9ms) curl http://127.0.0.1:9200/equity_contracts_development/_search?pretty -d '{"query":{"filtered":{"query":{"match_all":{}},"filter":{"and":[{"term":{"industry":"FOOD"}}]}}},"size":1,"from":0}'
=> #<Searchkick::Results:0x0000010b65c5c8
@klass=
EquityContract(id: integer, ticker: text, name: string, country: string, currency: string, instrument: string),
@options=
{:page=>1,
:per_page=>1,
:padding=>0,
:load=>false,
:includes=>nil,
:json=>false,
:match_suffix=>"analyzed",
:highlighted_fields=>[]},
@response=
{"took"=>1,
"timed_out"=>false,
"_shards"=>{"total"=>5, "successful"=>5, "failed"=>0},
"hits"=>{"total"=>0, "max_score"=>nil, "hits"=>[]}}>
如何更改此选项以使其更不区分大小写,从而使两者的结果相同?我看到Searchkiq生成术语查询,但您需要的是全文查询。我不熟悉Searchkiq,所以我不能告诉你怎么做 根据, 术语查询 像
术语
或模糊
查询这样的查询是没有分析阶段的低级查询。它们只在一个任期内运作。术语Foo的术语查询在倒排索引中查找确切的术语,并计算包含该术语的每个文档的TF/IDF相关性\u分数
全文查询
像match
或query\u string
这样的查询是理解字段映射的高级查询。。。如果查询全文(已分析)字段,他们将首先通过相应的分析器传递查询字符串,以生成要查询的术语列表
谢谢你愿意帮助埃瑟罗斯。有没有什么方法可以以过滤结果的方式来处理术语查询?我认为您可以在将数据存储到ES之前对数据进行降级,并在搜索之前对查询进行降级。我认为这可能是一个很好的解决方法。让我来试试。你能把你建议的解决办法和你的答案一起添加进来吗?这样我就可以接受。@EkiEqbal你能在哪里使它起作用?我也面临同样的问题。我尝试使用where:{name:/.*partial_name.*/I}where/I使regex大小写不敏感,但这在我的情况下不起作用,这取决于您对该字段
行业的映射<代码>术语
将与ES索引中的术语完全匹配,因此索引内容和方式很重要。
[23] pry(main)> EquityContract.search('*', {:load=>false, :where=>{:industry=>"Food"}, limit:1})
ETHON: performed EASY effective_url=http://127.0.0.1:9200/equity_contracts_development/_search response_code=200 return_code=ok total_time=0.002795
EquityContract Search (7.5ms) curl http://127.0.0.1:9200/equity_contracts_development/_search?pretty -d '{"query":{"filtered":{"query":{"match_all":{}},"filter":{"and":[{"term":{"industry":"Food"}}]}}},"size":1,"from":0}'
=> #<Searchkick::Results:0x000001112d1880
@klass=
EquityContract(id: integer, ticker: text, name: string, country: string, currency: string, instrument: string),
@options=
{:page=>1,
:per_page=>1,
:padding=>0,
:load=>false,
:includes=>nil,
:json=>false,
:match_suffix=>"analyzed",
:highlighted_fields=>[]},
@response=
{"took"=>1,
"timed_out"=>false,
"_shards"=>{"total"=>5, "successful"=>5, "failed"=>0},
"hits"=>
{"total"=>73,
"max_score"=>1.0,
"hits"=>
[{"_index"=>"equity_contracts_development_20160320195353552",
"_type"=>"equity_contract",
"_id"=>"1181",
"_score"=>1.0,
"_source"=>
{"name"=>"Some name",
"ticker"=>"some ticker",
"country"=>"SA",