title: How to search nested objects on Elasticsearch using elasticsearch.js and Angular
body: <p>I want to search fields on a nested document on my elasticsearch db. I use the following command to search fields on a nested object (getting 10 inner hits):</p>
  
  <pre><code>curl -X GET 'http://localhost:9200/jira-dev/_search?pretty=true' -d '
  {
  "_source" : false,
  "query" : {
      "nested" : {
          "path" : "issues",
          "query" : {
            "bool": {
              "should": [                   
                {
                  "wildcard":{
                    "issues.fields.description":"*migrate*"
                  } 
                },
                {
                  "wildcard":{
                    "issues.fields.comment.comments.body":"*autodeploy*"
                  } 
                }
              ]
            }               
          },
          "inner_hits" : {"size": 5000}
          }
      }   
  }'
  </code></pre>
  
  <p>But when I try to call it using elasticsearch.js in this way, it does not get any result:</p>
  
  <pre><code>client.search({
      index: 'jira-dev/',
      type: 'jira',
      body: {
          query: {
              nested : {
                  path : "issues",
                  query : {
                      bool: {
                          should: [                   
                          {
                              wildcard:{
                                  "issues.fields.description":"*migrate*"
                              } 
                          },
                          {
                              wildcard:{
                                  "issues.fields.comment.comments.body":"*autodeploy*"
                              } 
                          }
                          ]
                      }               
                  },
                  inner_hits : {size: 5000}
              }
            }
        }
  }).then(function (resp) {
      var hits = resp.hits.totals;
      console.log('works');
  }, function (err) {
      console.log('epic fail');
      console.trace(err.message);
  });
  </code></pre>
  
  <p>I suppose that the syntaxis that I am using is incorrect, but I have not found any example of nested queries using elasticsearch.js. </p>
  
  <p>Thanks in advance.</p>
  
  <p>Edit:</p>
  
  <p>As requested, following is the configuration of a document:</p>
  
  <pre><code>curl -X POST 'http://localhost:9200/jira-dev/' -d '{
      "mappings" : {
          "jira" : {
              "properties" : {
                  "expand" : {"type" : "string"},
                  "startAt" : {"type" : "integer"},
                  "maxResults" : {"type" : "integer"},
                  "total" : {"type" : "integer"},
                  "issues" : {
                      "type" : "nested",
                      "include_in_parent" : false,
                      "properties" : {
                          "created" : {"type" : "date", "format" : "date_hour_minute_second_fraction"}
                      }
                  }
              }
          }
      },
      "settings" : {
          "number_of_shards" : 5,
          "number_of_replicas" : 1
      }
  }'
  </code></pre>
  
  <p>and an example:</p>
  
  <pre><code>{
  
      "_index": "jira-dev",
      "_type": "jira",
      "_id": "1",
      "_version": 1,
      "_score": 1,
      "_source": {
          "expand": "schema,names",
          "startAt": 0,
          "maxResults": 1000,
          "total": 604,
          "issues": [
              {
  
                  "key": "STACK-1",
                  "fields": {
                      "summary": "A nice summary",
                      "created": "2016-06-28T09:45:32.000+0000",
                      "description": null,                    
                      "comment": {
                          "startAt": 0,
                          "maxResults": 1,
                          "total": 1,
                          "comments": [ 
                              {
                                  "self": url",
                                  "id": "30293",
                                  "author": {
                                      "name": "stack_overflow",
                                      "key": "stack_overflow"
                                  },
                                  "body": "Following epic has been created: url",
                                  "updateAuthor": {
                                      "name": "stack_overflow",
                                      "key": "stack_overflow",
                                      "timeZone": "Europe/Madrid"
                                  },
                                  "created": "2016-03-04T10:09:11.000+0000",
                                  "updated": "2016-03-04T10:09:11.000+0000"
                              }
                          ]
                      }
                  }
              }
          ]
      }
  }
  </code></pre>