# Can I score a document at index time?

**URL:** https://discuss.elastic.co/t/can-i-score-a-document-at-index-time/39803
**Category:** Elasticsearch
**Created:** [January 21, 2016, 5:07pm UTC](https://discuss.elastic.co/t/can-i-score-a-document-at-index-time/39803 "2016-01-21T17:07:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mattruzicka](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattruzicka/32/44809_2.png) [@mattruzicka](https://discuss.elastic.co/u/mattruzicka)
#### Post date: [January 21, 2016, 5:07pm UTC](https://discuss.elastic.co/t/can-i-score-a-document-at-index-time/39803/1 "2016-01-21T17:07:28Z")

</div>

I was wondering if there was a way to provide a query string when indexing a document so that the response from Elasticsearch could include the document's relevance score with regards to the provided query.

I suppose I'd only want something like this if scoring a document isn't relevant to other documents in the index (for efficiency reasons) and if it could be used with the bulk api. Honestly, I'm not sure if something like this would be any better than just indexing everything first and then doing the query.

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [January 21, 2016, 7:35pm UTC](https://discuss.elastic.co/t/can-i-score-a-document-at-index-time/39803/2 "2016-01-21T19:35:11Z")

</div>

"if there was a way to provide a query string when indexing a document so  
that the response from Elasticsearch could include the document's relevance  
score with regards to the provided query"

So basically you want to index some content to a field that would be used  
to search against? Sounds like exactly what Elasticsearch does. 🙂

Perhaps I misunderstood. You can always index a field whose value can be  
used as the score returned by a function score query, but that might be too  
simplistic:

[https://www.elastic.co/guide/en/elasticsearch/reference/2.1/query-dsl-function-score-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/2.1/query-dsl-function-score-query.html)

With Lucene, documents are not relevant to each other, only to the query  
used. Comparing documents returned in the same query is not suggested.

Cheers,

Ivan

---

<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, 2017, 11:22pm UTC](https://discuss.elastic.co/t/can-i-score-a-document-at-index-time/39803/3 "2017-07-05T23:22:25Z")

</div>


