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


(Anam Hossain) #1

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:

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

Data with geo location:

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

Data without geo location:

    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


(Christian Dahlqvist) #2

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.


(system) #3

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