pelias/query

do we need to specify the 'sort' param?

Opened this issue · 4 comments

All our queries have the following clause at the end which I believe is redundant?

It would be worth investigating further to confirm if _score is the default mode and if so we can remove this.

"sort": [
  "_score"
]

Also worth checking what track_scores does and if we still need that?

I just confirmed that all scores are zero or null for reverse queries. So I do believe that we can remove the _scores entry from sort for reverse at least.

Also, it look like the purpose of track_scores is to force Elasticsearch to compute and show scores even if the scores are not being used for sorting. So it sounds like we could immediately turn that off in all cases. For queries that use scores, it does nothing.

I had a look at the reverse queries this week for an unrelated reason and after some playing around with the queries, figured out a way of moving the geo distance scoring out of the sort section and into the body of the query, as a result, we would get scores where we didn't before.

I'm really not sure if that's the right thing to do or what the performance impact would be so I'll post an example here and we can look at it again later. I guess one benefit would be that the queries would be more similar to what we see for autocomplete and search when it comes to sorting.

{
    "query": {
        "bool": {
            "should": [
                {
                    "function_score": {
                        "functions": [
                            {
                                "linear": {
                                    "center_point": {
                                        "origin": {
                                            "lat": 1.317701,
                                            "lon": 103.849463
                                        },
                                        "scale": "1km",
                                        "offset": "0",
                                        "decay": 0.5
                                    }
                                }
                            }
                        ]
                    }
                }
            ],
            "filter": [
                {
                    "geo_distance": {
                        "distance": "1km",
                        "distance_type": "plane",
                        "center_point": {
                            "lat": 1.317701,
                            "lon": 103.849463
                        }
                    }
                }
            ]
        }
    },
    "size": 20,
    "sort": [
        "_score"
    ]
}

note: offset=0 is important here to score the closest matches correctly