# Explain a search against a particular document

**URL:** <https://discuss.elastic.co/t/explain-a-search-against-a-particular-document/6606>\
**Category:** Elasticsearch\
**Created:** [February 6, 2012, 5:25pm UTC](https://discuss.elastic.co/t/explain-a-search-against-a-particular-document/6606 "2012-02-06T17:25:09Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolas\_Lalevee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolas_lalevee/32/2892_2.png) [@Nicolas\_Lalevee](https://discuss.elastic.co/u/Nicolas_Lalevee)\
**Post date:** [February 6, 2012, 5:25pm UTC](https://discuss.elastic.co/t/explain-a-search-against-a-particular-document/6606/1 "2012-02-06T17:25:09Z")

</div>

Hi,

In order to do some debug I need to use the Lucene feature IndexSearcher#explain(Query q, int doc). I didn't find such API in Elasticsearch. Did I missed it ?

Nicolas

---

<div class="post-metadata">

**Author:** ![Mohit\_Chawla](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mohit_chawla/32/2243_2.png) [@Mohit\_Chawla](https://discuss.elastic.co/u/Mohit_Chawla)\
**Post date:** [February 6, 2012, 6:34pm UTC](https://discuss.elastic.co/t/explain-a-search-against-a-particular-document/6606/2 "2012-02-06T18:34:06Z")

</div>

Hello,

2012/2/6 Nicolas Lalevée [nicolas.lalevee@hibnet.org](mailto:nicolas.lalevee@hibnet.org):

> Hi,
> 
> In order to do some debug I need to use the Lucene feature IndexSearcher#explain(Query q, int doc). I didn't find such API in Elasticsearch. Did I missed it ?
> 
> Nicolas

I think you are looking for this :

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

---

<div class="post-metadata">

**Author:** ![Nicolas\_Lalevee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolas_lalevee/32/2892_2.png) [@Nicolas\_Lalevee](https://discuss.elastic.co/u/Nicolas_Lalevee)\
**Post date:** [February 6, 2012, 8:02pm UTC](https://discuss.elastic.co/t/explain-a-search-against-a-particular-document/6606/3 "2012-02-06T20:02:05Z")

</div>

Le 6 févr. 2012 à 19:34, Mohit Chawla a écrit :

> Hello,
> 
> 2012/2/6 Nicolas Lalevée [nicolas.lalevee@hibnet.org](mailto:nicolas.lalevee@hibnet.org):
> 
> > Hi,
> > 
> > In order to do some debug I need to use the Lucene feature IndexSearcher#explain(Query q, int doc). I didn't find such API in Elasticsearch. Did I missed it ?
> > 
> > Nicolas
> 
> I think you are looking for this :  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/explain.html)

Not exactly. The feature you're pointing me is about having explanation about the list of documents, the results of a query. I'm interested in the explanation of the score of a specific document against a query.

Nicolas

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 7, 2012, 10:12am UTC](https://discuss.elastic.co/t/explain-a-search-against-a-particular-document/6606/4 "2012-02-07T10:12:50Z")

</div>

No, there ins't an API for that, though we can add one (i.e. give a query and an ID, and explain it).

On Monday, February 6, 2012 at 10:02 PM, Nicolas Lalevée wrote:

> Le 6 févr. 2012 à 19:34, Mohit Chawla a écrit :
> 
> > Hello,
> > 
> > 2012/2/6 Nicolas Lalevée \<[nicolas.lalevee@hibnet.org](mailto:nicolas.lalevee@hibnet.org) ([mailto:nicolas.lalevee@hibnet.org](mailto:nicolas.lalevee@hibnet.org))\>:
> > 
> > > Hi,
> > > 
> > > In order to do some debug I need to use the Lucene feature IndexSearcher#explain(Query q, int doc). I didn't find such API in Elasticsearch. Did I missed it ?
> > > 
> > > Nicolas
> > 
> > I think you are looking for this :  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/explain.html)
> 
> Not exactly. The feature you're pointing me is about having explanation about the list of documents, the results of a query. I'm interested in the explanation of the score of a specific document against a query.
> 
> Nicolas

---

<div class="post-metadata">

**Author:** ![Nicolas\_Lalevee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolas_lalevee/32/2892_2.png) [@Nicolas\_Lalevee](https://discuss.elastic.co/u/Nicolas_Lalevee)\
**Post date:** [February 7, 2012, 1:22pm UTC](https://discuss.elastic.co/t/explain-a-search-against-a-particular-document/6606/5 "2012-02-07T13:22:16Z")

</div>

ok.  
If I have some spare cycles, I may propose a patch.

cheers,  
Nicolas

Le 7 févr. 2012 à 11:12, Shay Banon a écrit :

> No, there ins't an API for that, though we can add one (i.e. give a query and an ID, and explain it).  
> On Monday, February 6, 2012 at 10:02 PM, Nicolas Lalevée wrote:
> 
> > Le 6 févr. 2012 à 19:34, Mohit Chawla a écrit :
> > 
> > > Hello,
> > > 
> > > 2012/2/6 Nicolas Lalevée [nicolas.lalevee@hibnet.org](mailto:nicolas.lalevee@hibnet.org):
> > > 
> > > > Hi,
> > > > 
> > > > In order to do some debug I need to use the Lucene feature IndexSearcher#explain(Query q, int doc). I didn't find such API in Elasticsearch. Did I missed it ?
> > > > 
> > > > Nicolas
> > > 
> > > I think you are looking for this :  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/explain.html)
> > 
> > Not exactly. The feature you're pointing me is about having explanation about the list of documents, the results of a query. I'm interested in the explanation of the score of a specific document against a query.
> > 
> > Nicolas

---

<div class="post-metadata">

**Author:** ![Nicolas\_Lalevee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolas_lalevee/32/2892_2.png) [@Nicolas\_Lalevee](https://discuss.elastic.co/u/Nicolas_Lalevee)\
**Post date:** [March 28, 2012, 9:46am UTC](https://discuss.elastic.co/t/explain-a-search-against-a-particular-document/6606/6 "2012-03-28T09:46:23Z")

</div>

I implemented it, you can review it on my github [1]

I am not sure if I have put the code at the right place, if i should have put the code of TransportExplainAction#shardOperation in a SearchService or in a IndexService. Let me know what you think.

Nicolas

[1] [https://github.com/nlalevee/elasticsearch/tree/explain](https://github.com/nlalevee/elasticsearch/tree/explain)

Le 7 févr. 2012 à 14:22, Nicolas Lalevée a écrit :

> ok.  
> If I have some spare cycles, I may propose a patch.
> 
> cheers,  
> Nicolas
> 
> Le 7 févr. 2012 à 11:12, Shay Banon a écrit :
> 
> > No, there ins't an API for that, though we can add one (i.e. give a query and an ID, and explain it).  
> > On Monday, February 6, 2012 at 10:02 PM, Nicolas Lalevée wrote:
> > 
> > > Le 6 févr. 2012 à 19:34, Mohit Chawla a écrit :
> > > 
> > > > Hello,
> > > > 
> > > > 2012/2/6 Nicolas Lalevée [nicolas.lalevee@hibnet.org](mailto:nicolas.lalevee@hibnet.org):
> > > > 
> > > > > Hi,
> > > > > 
> > > > > In order to do some debug I need to use the Lucene feature IndexSearcher#explain(Query q, int doc). I didn't find such API in Elasticsearch. Did I missed it ?
> > > > > 
> > > > > Nicolas
> > > > 
> > > > I think you are looking for this :  
> > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/explain.html)
> > > 
> > > Not exactly. The feature you're pointing me is about having explanation about the list of documents, the results of a query. I'm interested in the explanation of the score of a specific document against a query.
> > > 
> > > Nicolas

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 28, 2012, 11:51am UTC](https://discuss.elastic.co/t/explain-a-search-against-a-particular-document/6606/7 "2012-03-28T11:51:12Z")

</div>

Looks good!. I think it requires some cleaning up (for example,  
ExplainDocResult is not used, and I don't think we need id on the explain  
source builder), but those are cosmetics :). Create a pull request?

2012/3/28 Nicolas Lalevée [nicolas.lalevee@hibnet.org](mailto:nicolas.lalevee@hibnet.org)

> I implemented it, you can review it on my github [1]
> 
> I am not sure if I have put the code at the right place, if i should have  
> put the code of TransportExplainAction#shardOperation in a SearchService or  
> in a IndexService. Let me know what you think.
> 
> Nicolas
> 
> [1] [https://github.com/nlalevee/elasticsearch/tree/explain](https://github.com/nlalevee/elasticsearch/tree/explain)
> 
> Le 7 févr. 2012 à 14:22, Nicolas Lalevée a écrit :
> 
> > ok.  
> > If I have some spare cycles, I may propose a patch.
> > 
> > cheers,  
> > Nicolas
> > 
> > Le 7 févr. 2012 à 11:12, Shay Banon a écrit :
> > 
> > > No, there ins't an API for that, though we can add one (i.e. give a  
> > > query and an ID, and explain it).  
> > > On Monday, February 6, 2012 at 10:02 PM, Nicolas Lalevée wrote:
> > > 
> > > > Le 6 févr. 2012 à 19:34, Mohit Chawla a écrit :
> > > > 
> > > > > Hello,
> > > > > 
> > > > > 2012/2/6 Nicolas Lalevée [nicolas.lalevee@hibnet.org](mailto:nicolas.lalevee@hibnet.org):
> > > > > 
> > > > > > Hi,
> > > > > > 
> > > > > > In order to do some debug I need to use the Lucene feature  
> > > > > > IndexSearcher#explain(Query q, int doc). I didn't find such API in  
> > > > > > Elasticsearch. Did I missed it ?
> > > > > > 
> > > > > > Nicolas
> > > > > 
> > > > > I think you are looking for this :  
> > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/explain.html)
> > > > 
> > > > Not exactly. The feature you're pointing me is about having  
> > > > explanation about the list of documents, the results of a query. I'm  
> > > > interested in the explanation of the score of a specific document against a  
> > > > query.
> > > > 
> > > > Nicolas

---

<div class="post-metadata">

**Author:** ![Nicolas\_Lalevee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolas_lalevee/32/2892_2.png) [@Nicolas\_Lalevee](https://discuss.elastic.co/u/Nicolas_Lalevee)\
**Post date:** [March 28, 2012, 6:17pm UTC](https://discuss.elastic.co/t/explain-a-search-against-a-particular-document/6606/8 "2012-03-28T18:17:16Z")

</div>

Le 28 mars 2012 à 13:51, Shay Banon a écrit :

> Looks good!. I think it requires some cleaning up (for example, ExplainDocResult is not used, and I don't think we need id on the explain source builder), but those are cosmetics :). Create a pull request?

done.

> <https://github.com/elastic/elasticsearch/pull/1817>
>
> The rest and client and transport implementations of a service to explain a part…icular document against a query

ExplainDocResult was indeed useless. I did also some cleanup of the javadoc.  
Note that the implementation I have done is mainly a copy/paste/merge of the /get and /search services, I don't understand every line in this patch, feel free to rework.

Next would be patching the doc. Maybe I'll have spare cycle tomorrow to do so.

cheers,  
Nicolas

> 2012/3/28 Nicolas Lalevée [nicolas.lalevee@hibnet.org](mailto:nicolas.lalevee@hibnet.org)  
> I implemented it, you can review it on my github [1]
> 
> I am not sure if I have put the code at the right place, if i should have put the code of TransportExplainAction#shardOperation in a SearchService or in a IndexService. Let me know what you think.
> 
> Nicolas
> 
> [1] [https://github.com/nlalevee/elasticsearch/tree/explain](https://github.com/nlalevee/elasticsearch/tree/explain)
> 
> Le 7 févr. 2012 à 14:22, Nicolas Lalevée a écrit :
> 
> > ok.  
> > If I have some spare cycles, I may propose a patch.
> > 
> > cheers,  
> > Nicolas
> > 
> > Le 7 févr. 2012 à 11:12, Shay Banon a écrit :
> > 
> > > No, there ins't an API for that, though we can add one (i.e. give a query and an ID, and explain it).  
> > > On Monday, February 6, 2012 at 10:02 PM, Nicolas Lalevée wrote:
> > > 
> > > > Le 6 févr. 2012 à 19:34, Mohit Chawla a écrit :
> > > > 
> > > > > Hello,
> > > > > 
> > > > > 2012/2/6 Nicolas Lalevée [nicolas.lalevee@hibnet.org](mailto:nicolas.lalevee@hibnet.org):
> > > > > 
> > > > > > Hi,
> > > > > > 
> > > > > > In order to do some debug I need to use the Lucene feature IndexSearcher#explain(Query q, int doc). I didn't find such API in Elasticsearch. Did I missed it ?
> > > > > > 
> > > > > > Nicolas
> > > > > 
> > > > > I think you are looking for this :  
> > > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/explain.html)
> > > > 
> > > > Not exactly. The feature you're pointing me is about having explanation about the list of documents, the results of a query. I'm interested in the explanation of the score of a specific document against a query.
> > > > 
> > > > Nicolas

---

<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:34am UTC](https://discuss.elastic.co/t/explain-a-search-against-a-particular-document/6606/9 "2017-07-06T03:34:16Z")

</div>


