# Problem with too long query time

**URL:** <https://discuss.elastic.co/t/problem-with-too-long-query-time/116417>\
**Category:** Elasticsearch\
**Created:** [January 22, 2018, 1:50am UTC](https://discuss.elastic.co/t/problem-with-too-long-query-time/116417 "2018-01-22T01:50:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chuckoh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chuckoh/32/26752_2.png) [@chuckoh](https://discuss.elastic.co/u/chuckoh)\
**Post date:** [January 22, 2018, 1:50am UTC](https://discuss.elastic.co/t/problem-with-too-long-query-time/116417/1 "2018-01-22T01:50:05Z")

</div>

A ES newbie here.

I've got documents in the following format and basically try to loop through all users data to find 2000 users within 100Km from his location excluding any users associated with the blocked\_ids.

```
{
    "name": "user1",
    "active": true,
    "location": { "lat": 21, "lon": 80 },
    "blocked_ids": ["19", "83", "486", ...]
},
{
    "name": "user2",
    "active": true,
    "location": { "lat": 22, "lon": 81 },
    "blocked_ids": ["7", "8", "148", ...]
},
:

```

So, first off, on my PHP application, I retrieve a chunk of every 200 users with scorll API. then, loop the chunk through with the following query:

```
    return [
        "index" => "users",
        "type" => "doc",
        "body" => [
            "size" => 2000,
            "query" => [
                "bool" => [
                    "must" => [
                        ["match" => [ "active" => true] ],
                    ],
                    "must_not" => [
                        "ids" => [
                            "values" => $excludedIds
                        ],
                    ],
                    "filter" => [
                        'geo_distance' => [
                            'distance' => "100km",
                            "distance_type" => "plane",
                            'location' => [
                                "lat" => $lat,
                                "lon" => $lng
                            ]
                        ]
                    ]
                ]
            ]
        ]
    ];

```

here, $excludedOds, $lat, and $lng are PHP variables extracted from the chunk. But, the execution time I measured was too long. I observed the size of query result, currently 2000, affect the execution time greatly. How can I achieve faster query result? Any tips or enlightments would greatly be appreciated.

Thanks!

Chuck

---

<div class="post-metadata">

**Author:** ![s1monw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/s1monw/32/3637_2.png) [@s1monw](https://discuss.elastic.co/u/s1monw)\
**Post date:** [January 26, 2018, 12:57pm UTC](https://discuss.elastic.co/t/problem-with-too-long-query-time/116417/2 "2018-01-26T12:57:56Z")

</div>

lemme ask some question?

- do you need these results all at once?
- is the query time acceptable if you set the size to 10?
- what is the time you get and what is the time you are looking for?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 23, 2018, 12:58pm UTC](https://discuss.elastic.co/t/problem-with-too-long-query-time/116417/3 "2018-02-23T12:58:15Z")

</div>

Closed on February 23, 2018, 12:58pm UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
