# ElasticSearch append non matched docs at the end of the search result

**URL:** <https://discuss.elastic.co/t/elasticsearch-append-non-matched-docs-at-the-end-of-the-search-result/148926>\
**Category:** Elasticsearch\
**Created:** [September 18, 2018, 6:31am UTC](https://discuss.elastic.co/t/elasticsearch-append-non-matched-docs-at-the-end-of-the-search-result/148926 "2018-09-18T06:31:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anam](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@anam](https://discuss.elastic.co/u/anam)\
**Post date:** [September 18, 2018, 6:31am UTC](https://discuss.elastic.co/t/elasticsearch-append-non-matched-docs-at-the-end-of-the-search-result/148926/1 "2018-09-18T06:31:18Z")

</div>

Is there any way to append non matched docs at the end of the search result?

I have been working on a project where we need to search docs by geolocation data but some docs don't have the geolocation data available. As a result of that these docs not returning in the search result.

Is there any way to append non matched docs at the end of the search result?

Example mapping:

```auto
        PUT /my_location
        {
            "mappings": {
                "_doc": {
                    "properties": {
                        "address": {
                            "properties": {
                                "city": {
                                    "type": "text"
                                },
                                "location": {
                                    "type": "geo_point"
                                }
                            }
                        }
                    }
                }
            }
        }

```

Data with geo location:

```auto
    PUT /my_locations/_doc/1
    {
        "address" : {
            "city: "XYZ",
            "location" : {
                "lat" : 40.12,
                "lon" : -71.34
            }
        }
    }

```

Data without geo location:

```auto
    PUT /my_locations/_doc/2
    {
        "address" : {
            "city: "ABC"
        }
    }

```

Is there any way to perform geo distance query which will select the docs with geolocation data plus append the non geo docs at the end of the result?

[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html#query-dsl-geo-distance-query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html#query-dsl-geo-distance-query)

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [September 19, 2018, 7:26am UTC](https://discuss.elastic.co/t/elasticsearch-append-non-matched-docs-at-the-end-of-the-search-result/148926/2 "2018-09-19T07:26:00Z")

</div>

I can't think of a way to do it in a single request, but you can easily send two separate queries in a single [multi search request](https://www.elastic.co/guide/en/elasticsearch/reference/6.4/search-multi-search.html).

---

<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:** [October 17, 2018, 7:37am UTC](https://discuss.elastic.co/t/elasticsearch-append-non-matched-docs-at-the-end-of-the-search-result/148926/3 "2018-10-17T07:37:28Z")

</div>

Closed on October 17, 2018, 7:37am UTC

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