Can I score a document at index time?

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.

"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. :slight_smile:

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

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