# Suggestions on how to tweak search accuracy

**URL:** <https://discuss.elastic.co/t/suggestions-on-how-to-tweak-search-accuracy/6305>\
**Category:** Elasticsearch\
**Created:** [January 6, 2012, 10:17pm UTC](https://discuss.elastic.co/t/suggestions-on-how-to-tweak-search-accuracy/6305 "2012-01-06T22:17:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shane\_Witbeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shane_witbeck/32/2803_2.png) [@Shane\_Witbeck](https://discuss.elastic.co/u/Shane_Witbeck)\
**Post date:** [January 6, 2012, 10:17pm UTC](https://discuss.elastic.co/t/suggestions-on-how-to-tweak-search-accuracy/6305/1 "2012-01-06T22:17:53Z")

</div>

I'd like to know what other people do to efficiently tweak searching (via  
boost, etc.) to get more accurate search results. I'm working to move from  
using Google Search Appliance to ES and the search results are wildly  
different.

---

<div class="post-metadata">

**Author:** ![Shane\_Witbeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shane_witbeck/32/2803_2.png) [@Shane\_Witbeck](https://discuss.elastic.co/u/Shane_Witbeck)\
**Post date:** [January 6, 2012, 10:37pm UTC](https://discuss.elastic.co/t/suggestions-on-how-to-tweak-search-accuracy/6305/2 "2012-01-06T22:37:21Z")

</div>

I should also mention I'm using the Java API and ES version 0.18.5. I've  
done some initial testing with changing boost values for a couple of fields  
but the values don't seem to have an impact. Do I need to also change boost  
values at index time for this to work? Here's an example of what I have:

boolQuery.must(  
queryString(terms)  
.analyzer("snowball")  
.field("message", 1)  
.field("subject", 3)  
);

Thanks.

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [January 7, 2012, 5:30pm UTC](https://discuss.elastic.co/t/suggestions-on-how-to-tweak-search-accuracy/6305/3 "2012-01-07T17:30:32Z")

</div>

On Fri, 2012-01-06 at 14:37 -0800, Shane Witbeck wrote:

> I should also mention I'm using the Java API and ES version 0.18.5.  
> I've done some initial testing with changing boost values for a couple  
> of fields but the values don't seem to have an impact. Do I need to  
> also change boost values at index time for this to work? Here's an  
> example of what I have:
> 
> boolQuery.must(  
> queryString(terms)  
> .analyzer("snowball")  
> .field("message", 1)  
> .field("subject", 3)  
> );

Hi Shane,

You'll need to provide more details. Currently we don't have much more  
info than "it doesn't do what i expect".

Put together a simple example using curl (see  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help) ) showing what you are doing, what  
results you get and how they are different from what you expect, and  
we'll be able to give you much more useful answers

clint

---

<div class="post-metadata">

**Author:** ![Shane\_Witbeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shane_witbeck/32/2803_2.png) [@Shane\_Witbeck](https://discuss.elastic.co/u/Shane_Witbeck)\
**Post date:** [January 9, 2012, 3:42pm UTC](https://discuss.elastic.co/t/suggestions-on-how-to-tweak-search-accuracy/6305/4 "2012-01-09T15:42:24Z")

</div>

Clinton, thanks for the reply. Apologies for not giving more information at  
the start. Here's more information:

> <https://gist.github.com/digitalsanctum/1583344>

The gist contains cluster health info, sample query, and meta including  
mapping for the "threads" index that I'm querying. Please let me know what  
else you may need.

My goal is to start applying tweaks to the index/search queries so that  
they match better with our existing search solution. As I mentioned before,  
I tried giving the "subject" field a higher boost value (3) in the search  
query and leaving the "message" boost value at (1) for the query "jboss ssl  
install". My desire is to boost documents that contain the query terms in  
the "subject" field. The "subject" field is typically much shorter in  
length and the "message" field can be very large. The context here is that  
this is searching forums where the "subject" field is the topic of the  
original forum post and the "message" field is an aggregate of the original  
forum body and all the reply posts.

Another goal is to return a lower number of total documents. ES seems to  
return many more (orders of magnitude) results based on the same queries.  
Is there a minimum score threshold setting to accomplish this?

I'm using the snowball analyzer here as well which I'm not familiar with so  
any pointers to in depth documentation on that would be nice too.

Thanks,  
Shane

---

<div class="post-metadata">

**Author:** ![Shane\_Witbeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shane_witbeck/32/2803_2.png) [@Shane\_Witbeck](https://discuss.elastic.co/u/Shane_Witbeck)\
**Post date:** [January 9, 2012, 4:27pm UTC](https://discuss.elastic.co/t/suggestions-on-how-to-tweak-search-accuracy/6305/5 "2012-01-09T16:27:28Z")

</div>

After doing some more testing I found that removing the sort dramatically  
improves search accuracy. What's the trick to having the accuracy AND apply  
a default sort? Here's the updated query without sort:

> <https://gist.github.com/digitalsanctum/1583682>

Thanks,  
Shane

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [January 9, 2012, 4:47pm UTC](https://discuss.elastic.co/t/suggestions-on-how-to-tweak-search-accuracy/6305/6 "2012-01-09T16:47:04Z")

</div>

Hi Shane

> My goal is to start applying tweaks to the index/search queries so  
> that they match better with our existing search solution. As I  
> mentioned before, I tried giving the "subject" field a higher boost  
> value (3) in the search query and leaving the "message" boost value at  
> (1) for the query "jboss ssl install". My desire is to boost documents  
> that contain the query terms in the "subject" field. The "subject"  
> field is typically much shorter in length and the "message" field can  
> be very large. The context here is that this is searching forums where  
> the "subject" field is the topic of the original forum post and the  
> "message" field is an aggregate of the original forum body and all the  
> reply posts.

OK - a few things here:

1. in your gist, you're actually boosting message and subject equally  
(ie 1.0)

2. you're then throwing away the score (relevance) and sorting by  
lastPostDate instead

3. your query is over-complicated by using and|or AND a bool query

Here is an example of your query that should produce good results:

> <https://gist.github.com/clintongormley/0d3b377fec9e2e9c333a>

And here is the same query but tweaked to boost (increase the relevancy)  
of posts made since 2011-01-01:

> <https://gist.github.com/clintongormley/c85de1c55e0e611c3f15>

clint

---

<div class="post-metadata">

**Author:** ![Shane\_Witbeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shane_witbeck/32/2803_2.png) [@Shane\_Witbeck](https://discuss.elastic.co/u/Shane_Witbeck)\
**Post date:** [January 9, 2012, 4:59pm UTC](https://discuss.elastic.co/t/suggestions-on-how-to-tweak-search-accuracy/6305/7 "2012-01-09T16:59:55Z")

</div>

Regarding #2, there's really no way to accomplish the more accurate  
(without sort) search THEN sort? If so, I'm thinking the thing to do here  
is NOT provide the default sort on the initial query so more accurate  
results are produced, then allow users to sort if they choose to. There are  
many other sorting fields I'm providing on the UI besides the date.

Thanks for your very helpful guidance and reworked queries!

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [January 9, 2012, 5:03pm UTC](https://discuss.elastic.co/t/suggestions-on-how-to-tweak-search-accuracy/6305/8 "2012-01-09T17:03:50Z")

</div>

On Mon, 2012-01-09 at 08:59 -0800, Shane Witbeck wrote:

> Regarding #2, there's really no way to accomplish the more accurate  
> (without sort) search THEN sort? If so, I'm thinking the thing to do  
> here is NOT provide the default sort on the initial query so more  
> accurate results are produced, then allow users to sort if they choose  
> to. There are many other sorting fields I'm providing on the UI  
> besides the date.

If you don't provide a sort parameter, then it defaults to:

sort: [{ "\_score": "asc" }]

So you can combine that with other sort parameters if you like

clint

---

<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 6, 2017, 3:43am UTC](https://discuss.elastic.co/t/suggestions-on-how-to-tweak-search-accuracy/6305/9 "2017-07-06T03:43:21Z")

</div>


