ElasticSearch - 与过滤器多重匹配 - 不返回任何结果

时间:2014-09-08 18:07:09

标签: elasticsearch

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

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

} }

首先,

  1. 是的,已有数据。
  2. 是没有错误
  3. 是的,没有拼写错误的单词
  4. 谢谢!

2 个答案:

答案 0 :(得分:1)

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

所以,我在之前的评论中没有看到这一点,但是如果您要查询的字段嵌套在正文中(在存储中 - 而不是在检索中),那么您需要一个{ {3}}以获取列出的字段(我不确定您是否正在描述您的映射或在查询检索中查找match_all的内容)

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

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

您可以使用扁平结构重新导入记录

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

答案 1 :(得分:0)

请尝试此查询:

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