0

I am trying to query my index and filtering according to geo-distance at the same time though paginate through my index but I ma getting this error

Error:

{
    "error": {
        "root_cause": [
            {
                "type": "parsing_exception",
                "reason": "bool query does not support [search_after]",
                "line": 7,
                "col": 21
            }
        ],
        "type": "parsing_exception",
        "reason": "bool query does not support [search_after]",
        "line": 7,
        "col": 21
    },
    "status": 400
}

Actual Query:

{
    "query": {
        "bool" : {
            "should" : {
                "match_all" : {}
            },
            "search_after": [1463538857, "654323"],
            "filter" : {
                "geo_distance" : {
                    "distance" : "150km",
                    "location" : {
                        "lat" : xxxx,
                        "lon" : xxxxx
                    }
                }
            }
        }
    }
 }

1 Answers1

0

Try to put search_after out of query:

{
    "query": {
        "bool" : {
            "should" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_distance" : {
                    "distance" : "150km",
                    "location" : {
                        "lat" : xxxx,
                        "lon" : xxxxx
                    }
                }
            }
        }
    }
    search_after": [1463538857, "654323"]
 }

So as name implies search_after will start matching after given value. You need to specify some ordering for that. For example in the example from documentation

GET twitter/_search
{
    "size": 10,
    "query": {
        "match" : {
            "title" : "elasticsearch"
        }
    },
    "search_after": [1463538857, "654323"],
    "sort": [
        {"date": "asc"},
        {"tie_breaker_id": "asc"}
    ]
}

first sorts documents based on date and tie_breaker_id fields so "search_after": [1463538857, "654323"] statement means begin searching after date 1463538857 and tie_breaker_id "654323"

So what you need to do here is to sort documents based on some field and after provide search_after with desired value.

alpert
  • 4,500
  • 1
  • 17
  • 27
  • Thank you I did what you say. The old error has gone now I am facing another could you help? "reason": "Sort must contain at least one field."" –  Feb 04 '20 at 18:12
  • Can you help with this question please https://stackoverflow.com/questions/60991499/elasticsearch-autocomplete-suggester?noredirect=1#comment107913286_60991499 –  Apr 03 '20 at 08:39