Apply a wildcard query to a nested object


(Abhijit Ghatnekar) #1

I have the below structure (small part of a very large elastic-search document)

sample: {
   {
       "md5sum":"4002cbda13066720513d1c9d55dba809",
       "id":1,
       "sha256sum":"1c6e77ec49413bf7043af2058f147fb147c4ee741fb478872f072d063f2338c5",
       "sha1sum":"ba1e6e9a849fb4e13e92b33d023d40a0f105f908",
       "created_at":"2016-02-02T14:25:19+00:00",
       "updated_at":"2016-02-11T20:43:22+00:00",
       "file_size":188416,
       "type":{
          "name":"EXE"
       },
       "tags":[

       ],
       "sampleSources":[
          {
             "filename":"4002cbda13066720513d1c9d55dba809",
             "source":{
                "name":"default"
             }
          },
         {
             "filename":"4002cbda13066720332513d1c9d55dba809",
             "source":{
                "name":"default"
             }
          }
       ]
    }
}

The filter I would like to use is to find by the 'name' contained within sample.sampleSources.source using elastic search. I would like to use the wildcard query for the name. Below is the query I am trying.

GET /app/sample/_search
    {
       "query": {
          "nested": {
             "path": "sampleSources.source",
             "query": {
                 "wildcard": {
                    "sampleSources.source.name": "def*"
                 }
             }
          }
       }
    } 

Below is the mapping

{  
   "app":{  
      "mappings":{  
         "sample":{  
            "sampleSources":{  
               "type":"nested",
               "properties":{  
                  "filename":{  
                     "type":"string"
                  },
                  "source":{  
                     "type":"nested",
                     "properties":{  
                        "name":{  
                           "type":"string"
                        }
                     }
                  }
               }
            }
         }
      }
   }
}

The elastic search version which I have is 1.5.2, lucene version 4.10.4. I don't see a reason why this not not work, can someone please guide?


(system) #2