在弹性搜索我试图多重搜索多个字段与多个值是可能吗? [英] In elasticsearch I'm trying to multi search multiple fields with multiple values is it possible?

查看:109
本文介绍了在弹性搜索我试图多重搜索多个字段与多个值是可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 卷曲-XDELETEhttp://127.0.0.1:9200 / data / _query-d'
{
multi_match:{
query:Will
fields:[firstname]
},{
query:Smith
fields:[lastname]
}
}'
/ pre>

似乎不起作用。



我做错了什么?谢谢

解决方案

很多Elasticsearch的文档缺少的一块是查询本身在一个查询(或 filter ),这意味着暗示。



现在,它们是具有不同值的不同字段,您可以在几个不同的方向进行,但我认为最好的选择是使用 bool query

  {
查询:{
bool:{
必须:[
{term:{firstname:Will}},
{term:{lastname:Smith}}
]
}
}
}

应该匹配:

  {
firstname:Will,
lastname:Smith
}

如果你有一个st结构如

  {
name:{
first:Will,
last:Smith
}
}

那么你只需将firstnamelastname更改为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 (or filter) 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屋!

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