Mike Shreek
Mike Shreek

Reputation: 215

ElasticSearch - multi-match with filter - returns no result

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!

Upvotes: 0

Views: 2978

Answers (2)

leavesof3
leavesof3

Reputation: 431

{
  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!"
}

Upvotes: 1

leavesof3
leavesof3

Reputation: 431

Try this query instead:

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

Upvotes: 0

Related Questions