在弹性搜索我试图多重搜索多个字段与多个值是可能吗? [英] In elasticsearch I'm trying to multi search multiple fields with multiple values is it possible?
问题描述
卷曲-XDELETEhttp://127.0.0.1:9200 / data / _query-d'
/ pre>
{
multi_match:{
query:Will
fields:[firstname]
},{
query:Smith
fields:[lastname]
}
}'
似乎不起作用。
我做错了什么?谢谢
解决方案很多Elasticsearch的文档缺少的一块是查询本身在一个
查询
(或filter
),这意味着暗示。
现在,它们是具有不同值的不同字段,您可以在几个不同的方向进行,但我认为最好的选择是使用
bool query
:{
查询:{
bool:{
必须:[
{term:{firstname:Will}},
{term:{lastname:Smith}}
]
}
}
}
应该匹配:
{
firstname:Will,
lastname:Smith
}
如果你有一个st结构如
{
name:{
first:Will,
last:Smith
}
}
那么你只需将
firstname
和lastname
更改为name.first code>和
name.last
。I have firstname and lastname mapped to "not_analyzed"
curl -XDELETE "http://127.0.0.1:9200/data/_query" -d' { "multi_match" : { "query": "Will" "fields": [ "firstname" ] },{ "query": "Smith" "fields": [ "lastname" ] } }'
It doesn't seem to work.
What am I doing wrong? Thanks
解决方案The missing piece to a lot of Elasticsearch's documentation is that the queries are themselves within a
query
(orfilter
) and that is meant to be implied.Now, since they are different fields with different values, you can go in a few different directions, but I think that the best option would be to use a
bool query
:{ "query" : { "bool" : { "must" : [ { "term" : { "firstname" : "Will" } }, { "term" : { "lastname" : "Smith" } } ] } } }
That should match:
{ "firstname" : "Will", "lastname" : "Smith" }
If you had a structure like
{ "name" : { "first" : "Will", "last" : "Smith" } }
then you would just change
"firstname"
and"lastname"
to"name.first"
and"name.last"
respectively.这篇关于在弹性搜索我试图多重搜索多个字段与多个值是可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!