Valentin Garreau
Valentin Garreau

Reputation: 1063

How to filter many value in same time?

I'm using elastic search to filter 1 document and i use a loop to filer many documents. But now i want to filter many document in one request to optimize my script.

For the moment i have this query, and i'm using a "for" loop to filter by uuid.

for id in id_list:
    filter (id)

def filter(id): 

    result = requests.get(
            settings + '/data/_search?size=10000',
            json={
                "query": {
                    "bool": {
                        "filter": {
                            "terms": {
                                "id": id
                            }
                        }
                    }
                },
                "_source": {
                    "exclude": ["type", "date"]
                }
            }
        )

I would like to do only one request to get all my document at once to optimize my code.

Upvotes: 1

Views: 40

Answers (1)

aHochstein
aHochstein

Reputation: 515

The terms query takes an array of arguments, see the reference for an example.

Upvotes: 2

Related Questions