Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do we need to specify the 'sort' param? #115

Open
missinglink opened this issue Nov 14, 2019 · 4 comments
Open

do we need to specify the 'sort' param? #115

missinglink opened this issue Nov 14, 2019 · 4 comments

Comments

@missinglink
Copy link
Member

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"
]
@missinglink
Copy link
Member Author

missinglink commented Nov 14, 2019

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

@missinglink
Copy link
Member Author

@orangejulius
Copy link
Member

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.

@missinglink
Copy link
Member Author

missinglink commented Dec 11, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants