elastic / go-elasticsearch

The official Go client for Elasticsearch
https://github.com/elastic/go-elasticsearch#go-elasticsearch
Apache License 2.0
5.54k stars 609 forks source link

TypedClient: Search parameters "size" and "from" seem to be ignored #822

Closed HaraldNordgren closed 4 months ago

HaraldNordgren commented 4 months ago

I construct my query like this:

    res, err := p.client.
        Search().
        Index(p.index).
        From(from).
        Size(size).
        Request(constructRequest(searchTerm)).
        Do(ctx)
    if err != nil {
        return nil, err
    }

It always gives me 10 results back. I can hard-code values like this and the result is still only 10 results back:

        From(0).
        Size(1)

I verified that by setting it directly on the search.Request works:

    res, err := p.client.
        Search().
        Index(p.index).
        Request(&search.Request{
            Query: &types.Query{},
            From:  &from,
            Size:  &size,
        }).
        Do(ctx)

These function should be deleted if they are not usable.

Anaethelion commented 4 months ago

Hi @HaraldNordgren

What is happening is the Request call in your first example is overwriting the request object thus resetting the values set above. If you intend to use the From and Size functions you should also use the Query to set the query arguments, otherwise the second syntax works fine and as intended.