简体   繁体   中英

Elastic Search Getting Results Based On a Field Value

For my elastic search index books as given,

{
    "books": [
        {
            "id": 1,
            "title": "Title 1",
            "store": "store1" ,
            "bookid": "01"
        },
        {             
            "id": 2,
            "title": "Title 1",
            "store": "store2" ,
            "bookid": "01"
        },
        {             
            "id": 4,
            "title": "Title 2",
            "store": "store2" ,
            "bookid": "02"
        },
        {             
            "id": 5,
            "title": "Title 2",
            "store": "store3" ,
            "bookid": "02"
        },
        {             
            "id": 6,
            "title": "Title 2",
            "store": "store3" ,
            "bookid": "02"
        },
        {             
            "id": 7,
            "title": "Title 1",
            "store": "store3" ,
            "bookid": "03"
        }
    ]
}

Now to get two books per page if I pass " "from" : 0, "size" : 2 ", I will get only the first two records as by default.

Now here the number of records related to one book id may be very. That is Book 01 may have 2 records in Elastic Search, while Book 02 may have 3 or 4.

So how could I form a query which for each page gets me two Books that is in this case All the five records which forms the 2 books.

Is there a way I could achieve this like group by or aggregation?

重塑了架构以具有父数组和子数组。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM