javaelasticsearchnestedelasticsearch-jest

Elasticsearch return nested objects without their parents


I have an index that looks like this:

{
    "mappings":{
        "authors":{
            "properties":{
                "books":{
                    "type":"nested",
                    "properties":{
                        "title":{"type":"string"},
                        "firstSentence":{"type":"string"},
                        "isbn":{"type":"string"},
                        "publishDate":{"type":"date"},
                    }
                },
                "firstName":{"type":"string"},
                "lastName":{"type":"string"}, 
                "birthday":{"type":"date"},
                }
           }
}

I am querying this index through a Java client. For this query, I don't care about the authors; all I want to get back are books. For instance, I would like to find all books with the word "Hello" in the title and in the first sentence.

Currently, I use a nested query that returns a list of authors, and then I manually parse that list to get the books. Is there a way to get Elasticsearch to directly return a list of books? I am using Elasticsearch version 1.5.2, and Jest 0.1.6


Solution

  • No, the results are the documents that you inject. You can use source filtering to limit the fields of the documents that are returned, that way you can only get back the nested docs. But these will always be in the scope of the nested parent. So if you find two authors with each a few books, you get back two results with the nested docs in there.

    https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-source-filtering.html#search-request-source-filtering