Home > Back-end >  Why this query has 0 hits?
Why this query has 0 hits?

Time:05-21

I have a document with ID of "students" in an index named "university". The document has the following content:

{
   "1234567": {
      name: "Jack",
      subject: "Computer Engineering"
   }
   "7654321": {
      name: "John",
      subject: "Computer Engineering"
   }
}

I want to search for students with name "John". I came up with the following query in Kibana:

GET /university/_search
{
   "query": {
      "match": {
         "*.name": "John"
      }
   }
}

But this query has 0 hits. Why? What is the correct query?

CodePudding user response:

The match query doesn't support wildcarded field names. Use multi_match instead:

GET /university/_search
{
   "query": {
      "multi_match": {
         "query":    "John", 
         "fields": [ "*.name" ] 
      }
   }
}
  • Related