markov00
markov00

Reputation: 3722

Elasticsearch how to return the number of maching term for each document

I'm very new to elasticsearch and I'm interested in how is possible to retrieve the number of matching term inside each document processed. I know that I can get a score, but I'm looking to get number of matches for each document, is it possible?

Edit after mguillermin answer

What I was looking to is to query my index, and receive at the same time the tf on each document result, and not simply to find the term frequency of a single document

Thanks

Upvotes: 2

Views: 1631

Answers (1)

mguillermin
mguillermin

Reputation: 4181

For checking a single document, you can retrieve this kind of information using the explain API : http://www.elasticsearch.org/guide/reference/api/explain/

If you need this information collected along with the query results, you can just add the "explain": true to the body sent to the _search. Ex :

{
    "explain": true,
    "query": {
        "term": {
           "description": "test"
        }
    }
}

With this parameter, you will get for each hit the associated _explanation data. Ex :

"_explanation": {
   "value": 1.4845161,
   "description": "fieldWeight(description:test in 63), product of:",
   "details": [
      {
         "value": 1,
         "description": "tf(termFreq(description:test)=1)"
      },
      {
         "value": 5.9380646,
         "description": "idf(docFreq=23, maxDocs=3348)"
      },
      {
         "value": 0.25,
         "description": "fieldNorm(field=description, doc=63)"
      }
   ]
}

Upvotes: 4

Related Questions