我使用ElasticSearch
与Ruby(Searchkick
)。目前,默认情况下,where过滤器区分大小写。
我在我的EquityContract
模型中使用ElasticSearch,因此一旦我搜索Food
,我会得到不同的结果来搜索food
。
[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"=>[]}}>
当我使用Food
执行相同操作时,我得到了一些结果:
[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",
如何更改此设置以使其更不区分大小写,以便我们对两者都有相同的结果?
答案 0 :(得分:1)
我看到Searchkiq会生成术语查询,但您需要的是全文查询。我对Searchkiq并不熟悉所以我无法告诉你如何。
根据the documentation on ElasticSearch official website,
term
或fuzz
查询等查询是没有分析阶段的低级查询。他们只用一个学期。术语 Foo 的术语查询在倒排索引中查找该确切术语,并为包含该术语的每个文档计算TF / IDF相关性_score
。
match
或query_string
查询之类的查询是了解字段映射的高级查询...如果查询全文(已分析)字段,它们将首先通过通过适当的分析器查询字符串以生成要查询的术语列表。