# How to prioritize some products in Elasticsearch

**URL:** <https://forum.litium.com/t/how-to-prioritize-some-products-in-elasticsearch/2013>\
**Category:** Questions\
**Tags:** litium-7\
**Created:** [April 21, 2021, 8:46am UTC](https://forum.litium.com/t/how-to-prioritize-some-products-in-elasticsearch/2013 "2021-04-21T08:46:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishnu\_kj](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/vishnu_kj/32/685_2.png) [@vishnu\_kj](https://forum.litium.com/u/vishnu_kj)\
**Post date:** [April 21, 2021, 8:46am UTC](https://forum.litium.com/t/how-to-prioritize-some-products-in-elasticsearch/2013/1 "2021-04-21T08:46:33Z")

</div>

How can I prioritize products in Elasticsearch results, is there a way that i can get the search result by changing the score or by adding tags?  
Litium version 7.6.1

---

<div class="post-metadata">

**Author:** ![Artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/artur/32/948_2.png) [@Artur](https://forum.litium.com/u/Artur)\
**Post date:** [April 21, 2021, 9:53am UTC](https://forum.litium.com/t/how-to-prioritize-some-products-in-elasticsearch/2013/2 "2021-04-21T09:53:04Z")

</div>

There is a boost attribute that should do it. But there is no backoffice to control it though.  
So you would need to add a field somewhere to later add it when it sorts.

---

<div class="post-metadata">

**Author:** ![NilsN](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/nilsn/32/302_2.png) [@NilsN](https://forum.litium.com/u/NilsN)\
**Post date:** [April 21, 2021, 3:09pm UTC](https://forum.litium.com/t/how-to-prioritize-some-products-in-elasticsearch/2013/3 "2021-04-21T15:09:49Z")

</div>

It depends on how you want to boost I guess. Could you explain the requirements a bit more?

You can apply Boost to a particular field to have hits from there be scored higher.

```auto
if (!string.IsNullOrWhiteSpace(searchQuery.Text))
{
	allQueries.Add((qc.Match(x => x.Field(z => z.Name).Query(searchQuery.Text).Fuzziness(Fuzziness.Auto).Boost(10).SynonymAnalyzer())
					|| qc.Match(x => x.Field(z => z.ArticleNumber).Query(searchQuery.Text.ToLower()).Boost(2))
					|| qc.Match(x => x.Field(z => z.Content).Query(searchQuery.Text).Fuzziness(Fuzziness.Auto).SynonymAnalyzer())));
}

```

You can also add a boost if the field contains a specific value:

```auto
allQueries.Add((qc.Match(x => x.Field(z => z.Name).Query(searchQuery.Text).Fuzziness(Fuzziness.Auto).Boost(10).SynonymAnalyzer())
				|| qc.Match(x => x.Field(z => z.ArticleNumber).Query(searchQuery.Text.ToLower()).Boost(2))
				|| qc.Match(x => x.Field(z => z.Content).Query(searchQuery.Text).Fuzziness(Fuzziness.Auto).SynonymAnalyzer())
				|| qc.Match(x => x.Field(z => z.Content).Query("my_value").Boost(100))));

```

You can filter on properties on the `ProductDocument` itself, in this example a property `InStock` has been added.  
`allQueries.Add(qc.Bool(b => b.Filter(bf => bf.Term(t => t.Field(x => x.InStock).Value(true)))));`

You can also add a weight if a field contains a predetermined value. Here we are boosting a particular brand.

```auto
allQueries.Add(qc.Nested(n => n
	.Path(p => p.Tags)
	.Query(q => q
		.FunctionScore(fs => fs
			.Functions(fu => fu
				.Weight(w => w
					.Weight(42)
					.Filter(wf => wf
						.Term(t => t
							.Field(f => f.Tags[0].Key).Value(BrandListViewModel.TagName)
							.Field(f => f.Tags[0].Value).Value(boostedBrand)
))))))));

```

---

<div class="post-metadata">

**Author:** ![vishnu\_kj](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/vishnu_kj/32/685_2.png) [@vishnu\_kj](https://forum.litium.com/u/vishnu_kj)\
**Post date:** [April 23, 2021, 9:29am UTC](https://forum.litium.com/t/how-to-prioritize-some-products-in-elasticsearch/2013/4 "2021-04-23T09:29:02Z")

</div>

Thank You @Artur for the quick replay

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/12eddac3b8b661de1db86af10ac8151b571e6fb9.png) [@system](https://forum.litium.com/u/system)\
**Post date:** [May 21, 2021, 9:29am UTC](https://forum.litium.com/t/how-to-prioritize-some-products-in-elasticsearch/2013/5 "2021-05-21T09:29:46Z")

</div>

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