Stewart
Stewart

Reputation: 3161

Returning term count for a single document using the terms facet in elastic search

Say I have the following search query...

POST /topics/_search
{
    "fields": [
       "topic_attachment",
       "topic_replies",
       "topic_status"
    ],
    "query" : {
        "filtered" : {
            "query" : {
                "term" : { 
                    "_id" : "5478"
                }
            }
        }           
    },
    "facets": {
       "text": {
          "terms": {
             "field": "text",
             "size": 10,
             "order": "count"
            }
       }
    }
}

The result of this search is the following.

{
   "took": 93,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 1,
      "hits": [
         {
            "_index": "topics",
            "_type": "full-topic",
            "_id": "5478",
            "_score": 1,
            "fields": {
               "topic_replies": 1141,
               "topic_status": 0,
               "topic_attachment": false
            }
         }
      ]
   },
   "facets": {
      "text": {
         "_type": "terms",
         "missing": 0,
         "total": 8058,
         "other": 8048,
         "terms": [
            {
               "term": "ω",
               "count": 1
            },
            {
               "term": "œyouâ",
               "count": 1
            },
            {
               "term": "œyou",
               "count": 1
            },
            {
               "term": "œwhisperedâ",
               "count": 1
            },
            {
               "term": "œwalt",
               "count": 1
            },
            {
               "term": "œunderstandingâ",
               "count": 1
            },
            {
               "term": "œtieâ",
               "count": 1
            },
            {
               "term": "œthe",
               "count": 1
            },
            {
               "term": "œpersonally",
               "count": 1
            },
            {
               "term": "œnappiesâ",
               "count": 1
            }
         ]
      }
   }
}

Each term has a count of exactly 1. Why is this? I know the text from this document has more than one term in common. Is this because the term count only increments once per document? If so how do I count a term more than once from a single document?

Upvotes: 0

Views: 762

Answers (1)

javanna
javanna

Reputation: 60245

That's the document count, not the term frequency. Luckily with the new aggregations module (replacement for facets introduced in 1.0.Beta2) count has been renamed to doc_count to clarify what it is.

Upvotes: 3

Related Questions