1

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):

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}
        }
    }   
}'

But when I try to call it using elasticsearch.js in this way, it does not get any result:

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);
});

I suppose that the syntaxis that I am using is incorrect, but I have not found any example of nested queries using elasticsearch.js.

Thanks in advance.

Edit:

As requested, following is the configuration of a document:

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
    }
}'

and an example:

{

    "_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"
                            }
                        ]
                    }
                }
            }
        ]
    }
}
2
  • Could you give an example of how the structure of your documents look? Commented Jul 5, 2016 at 19:38
  • For sure, I have added an example and the configuration Commented Jul 6, 2016 at 8:31

1 Answer 1

0

Finally, to skip this issue I has used a middleware server between angular and elastic. This server is a python server and is easy to do GET/POST on elasticsearch via curl.

Moreover, I tried to use curl directly from Angular (html GET), but due to convention, an html server can ignore data on a GET petition. Therefore, via curl from Angular it was impossible to do petitions on elastic.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.