# How to improve query using test data and expected result

**URL:** <https://discuss.elastic.co/t/how-to-improve-query-using-test-data-and-expected-result/158963>\
**Category:** Elasticsearch\
**Created:** [November 30, 2018, 8:31pm UTC](https://discuss.elastic.co/t/how-to-improve-query-using-test-data-and-expected-result/158963 "2018-11-30T20:31:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmr317](https://avatars.discourse-cdn.com/v4/letter/j/977dab/32.png) [@jmr317](https://discuss.elastic.co/u/jmr317)\
**Post date:** [November 30, 2018, 8:31pm UTC](https://discuss.elastic.co/t/how-to-improve-query-using-test-data-and-expected-result/158963/1 "2018-11-30T20:31:40Z")

</div>

I have a test set of data that includes a search string and the document id of the document that would be of highest relevance for that search string. Is there a specific way I can go about improving my query (currently just a multi match across multiple fields) so that that the most relevant documents are returning higher in my results?

Right now I'm just randomly picking boosts and cutoff\_frequency's and running my training set through queries to see which query I've randomly created gives me the best result. Is there a more optimal way I could be doing this?

---

<div class="post-metadata">

**Author:** ![softwaredoug](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/softwaredoug/32/22681_2.png) [@softwaredoug](https://discuss.elastic.co/u/softwaredoug)\
**Post date:** [November 30, 2018, 9:00pm UTC](https://discuss.elastic.co/t/how-to-improve-query-using-test-data-and-expected-result/158963/2 "2018-11-30T21:00:03Z")

</div>

This is a complex topic, some have even written books on it 😉

What you have is close to what's known as a judgment list: a set of graded documents for each query. There's a lot of standard metrics for taking a judgment list and coming up with a number on how good the results are:

Like:

[https://en.wikipedia.org/wiki/Discounted\_cumulative\_gain](https://en.wikipedia.org/wiki/Discounted_cumulative_gain)

[https://en.wikipedia.org/wiki/Precision\_and\_recall](https://en.wikipedia.org/wiki/Precision_and_recall)

You can also use tools that are built to use judgment lists and evaluate the quality of a search relevance solution:

[http://quepid.com](http://quepid.com)

[https://sease.io/2018/07/rated-ranking-evaluator.html](https://sease.io/2018/07/rated-ranking-evaluator.html)

On the solution - If you have good metrics you could trust, you could do a grid search on a set of parameters on your current query strategy.

BUT you'll only do good with proportion to the quality of the underlying queries. Just like machine learning is only as good as the underlying features. And that's the hard stuff people spend years on both inside and outside the search engine with complex enrichment of docs and queries. What you need to do is try to craft good ranking-time signals that turn a relevance score into something closer to what users care about when it comes to relevance, see here:

[https://opensourceconnections.com/blog/2015/05/15/relevance-data-modeling/](https://opensourceconnections.com/blog/2015/05/15/relevance-data-modeling/)

IF you have good enough signals AND you have a lot of high quality judgments, you MIGHT be in a position where you could turn the ranking optimization into a machine learning problem:

[https://opensourceconnections.com/blog/2017/02/24/what-is-learning-to-rank/](https://opensourceconnections.com/blog/2017/02/24/what-is-learning-to-rank/)

So I'm not sure if that helps other than just opens a pandoras box of stuff to learn about...

---

<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:** [December 28, 2018, 9:04pm UTC](https://discuss.elastic.co/t/how-to-improve-query-using-test-data-and-expected-result/158963/3 "2018-12-28T21:04:12Z")

</div>

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