# ElasticSearch how best to prioritise results based on integer / keyword

**URL:** <https://discuss.elastic.co/t/elasticsearch-how-best-to-prioritise-results-based-on-integer-keyword/184594>\
**Category:** Elasticsearch\
**Created:** [June 6, 2019, 1:47pm UTC](https://discuss.elastic.co/t/elasticsearch-how-best-to-prioritise-results-based-on-integer-keyword/184594 "2019-06-06T13:47:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamtoms](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@adamtoms](https://discuss.elastic.co/u/adamtoms)\
**Post date:** [June 6, 2019, 1:47pm UTC](https://discuss.elastic.co/t/elasticsearch-how-best-to-prioritise-results-based-on-integer-keyword/184594/1 "2019-06-06T13:47:45Z")

</div>

I have a catalog of neoprene products that I would like to search. I'm interesting in how to achieve a search by thickness. Product names will contain the thickness along with a thickness field that contains the upper value, i.e. `thickness:6mm`

> name: Rip Curl 6/5/4mm wetsuit  
> name: Rip Curl 3mm

Respective thickness properties

> Thickness:6mm  
> Thickness:3mm

When a search is performed for 3mm I would like to prioritize all results that match exactly 3mm, before 4/3mm and 5/4/3mm etc.

Then when 4/3mm is searched I would like prioritize 4/3mm, 5/4/3mm and then 3mm.

The user may search in any of these terms, note that `mm` may be excluded.

5mm wetsuit  
6/5/4mm wetsuit  
4/5/6mm wetsuit  
3 4mm wetsuit  
3/4mm wetsuit  
3-4mm wetsuit  
3/4 wetsuit  
3 4 wetsuit

I've thought about doing a keyword comparison on the 'thickness' field for the max int provided in the search. Then a text search for the other params.

Additionally, I've thought of parsing the data using a regex such as `[\d\/m-]*` (will select just the int ranges).

I could expand the product data out before inserting. So I would place each size in a keyword array but then I would still need to find the closest match and set a limit of what sort of matching is allowed. Maybe using something like the `ngram_tokenizer`

Please could someone advise how best to achieve this functionality and what tools would be best suited? I'm not after an example, more just to be pointed in the right direction.

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [June 7, 2019, 7:27am UTC](https://discuss.elastic.co/t/elasticsearch-how-best-to-prioritise-results-based-on-integer-keyword/184594/2 "2019-06-07T07:27:56Z")

</div>

Hi,

What you want is prioritize the exact match?  
if so you can use "term" with a high boost inside a bool should with a "match" having lower boost so your document with exact match 3mm will be before the 3/4 mm, as both document will match.

[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html)

Hope it help.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2019, 7:27am UTC](https://discuss.elastic.co/t/elasticsearch-how-best-to-prioritise-results-based-on-integer-keyword/184594/3 "2019-07-05T07:27:58Z")

</div>

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