ElasticSearch - 与过滤器的多重匹配 - 不返回任何结果 [英] ElasticSearch - multi-match with filter - returns no result

查看:595
本文介绍了ElasticSearch - 与过滤器的多重匹配 - 不返回任何结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题。在我的JSON请求中添加过滤器时,我的搜索结果将返回0

  {
body:
{
query:{
multi_match:
{
查询:Joe Jerick Aparments,
fields:[name ,类别,地址,描述]}
},
过滤器:
{
源:类别:公寓
}

}
}



首先,首先,


  1. 是的,已经有数据。

  2. 是的没有错误

  3. 是的,没有拼写错误的单词

谢谢!

解决方案

  {
index:stores,
type:stores,
id:1,
body:{
name:Joe Jerick Apartments,
类别:公寓
地址:某处下路
描述:最好的公寓!
}
}

所以,我没有在我的早期看到评论,但如果您要查询的字段嵌套在正文内(在存储 - 不在检索)中,您需要一个嵌套查询来获取列出的字段(我不知道你是否描述你的映射或它的外观像一个match_all的查询检索一样)



如果是这种情况,你需要将body映射为嵌套,然后你的查询看起来就像这样。

  {
query:{
filtered:{
query :{
multi_match:{
query:Joe Jerick Apartments,
fields:[
body.name,
body .Category,
body.address,
body.description
]
}
},
过滤器:{
term:{
body.Category:Apartments
}
}
}
}
}

以扁平结构重新导入您的记录

  {
id:1,
名字:Joe Jerick公寓,
类别:公寓,
地址:某处下路,
描述:最好的公寓!
}


I have a problem. My search result returns zero when I add a filter in my JSON request

{
 "body":
   {
      "query":{
         "multi_match":
               {
              "query":"Joe Jerick Aparments",
              "fields":["name","Category","address","description"]}
       },
   "filter":
        {
           "source":"Category":"Apartments"
      }

} }

First things first,

  1. Yes, there is already data.
  2. Yes there is no error
  3. Yes there is no misspelled words

Thanks!

解决方案

{
  index: "stores",
  type: "stores",
  id: "1",
  body: {
    name: "Joe Jerick Apartments",
    Category: "Apartments"
    address: "Somewhere down the road",
    description: "Best apartment yet!"
  }
} 

So, I didn't see this in my earlier comment but if the fields you're querying on are nested inside of body (in storage -- not in retrieval) you'll need a nested query to get at the fields listed (I'm not sure if you're describing your mapping or what it looks like on query retrieval for a match_all)

If this is the case you'll need body to be mapped as "nested" and then your query would look something like this.

{
    "query": {
      "filtered": {
        "query": {
          "multi_match": {
            "query": "Joe Jerick Apartments",
            "fields": [
              "body.name",
              "body.Category",
              "body.address",
              "body.description"
            ]
          }
        },
        "filter": {
          "term": {
            "body.Category": "Apartments"
          }
        }
      }
    }
}

Altertively you could re-import your records with a flattened structure

{
  "id": "1",
  "name": "Joe Jerick Apartments",
  "Category": "Apartments",
  "address": "Somewhere down the road",
  "description": "Best apartment yet!"
}

这篇关于ElasticSearch - 与过滤器的多重匹配 - 不返回任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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