Inconsistent result order (same score)

Here's what I am trying to accomplish,

Documents are categorized into category names and I am trying to fetch all documents under a certain category. This works out as expected using the following snippet,

'index' => 'test_index',
'type' => 'test_type',
'body' => [
	'from' => 0,
	'size' => 20,
	'query' => [
		'bool' => [
			'must' => [
				'match_phrase' => [
					'cat_name' => 'elastic'
				]				
			]
		]
	]
]

The problem is the result order changes each time the query is run and seeing that the scores returned are all the same (at-least on the first page), I believe this is the reason.

To get around this, I came across preference parameter which tries to keep things consistent but this would not work if the same query was run by a different user (think a website user).

Another alternative is to wrap this in a dis max query with tie_breaker but I believe this isn't what I am looking for considering there would be just one bool query in it.

I have been looking around the documentation and it feels like I am overthinking this a bit too much.

Any help will be appreciated :slight_smile:

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