quey_string搜索无法正常工作 [英] quey_string search is not working as expected
本文介绍了quey_string搜索无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
{ _id:1,name:Doeman John}
pre>
{_id:2,name:John}
使用查询: -
{
查询:{
query_string:{
fields:[name],
query:John
}
}
}
实际结果: -
{_id: 1,name:Doeman John}
{_id:2,name:John}
预期结果: -
code> {_ id:2,name:John}
我正在使用标准分析仪。
解决方案可以实现我的
预期结果
您不能在不更改分析器
设置的情况下实现此目的。
如果您还想使用标准分析器
,您可以使您的字段multifield
。{
mappings:{
my_type:{
properties:{
name:{
type:text,
fields:{
raw:{
type:keyword
}
}
}
}
}
}
}
,然后在
not_analyzed
版本上运行您的查询。{
query:{
term:{
name.raw:{
value:John
}
}
}
}
这将根据您的要求提取结果。
`
Suppose We have data :-
{ "_id" : "1","name" : "Doeman John"} {"_id" : "2","name" : "John"}
Query Used :-
{ "query": { "query_string": { "fields" : ["name"] , "query": "John" } } }
Actual result :-
{ "_id" : "1","name" : "Doeman John"} {"_id" : "2","name" : "John"}
Expected result :-
{"_id" : "2","name" : "John"}
I am using Standard Analyzer . Could I achieve my
expected result
without changing any Analyzer setting ?解决方案You can not achieve this without changing
analyzer
settings. In case you still want to useStandard Analyzer
, you can make your fieldmultifield
.{ "mappings": { "my_type": { "properties": { "name": { "type": "text", "fields": { "raw": { "type": "keyword" } } } } } } }
and then run your query on the
not_analyzed
version.{ "query": { "term": { "name.raw": { "value": "John" } } } }
This will fetch results as per your requirement.
`
这篇关于quey_string搜索无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文