maaz
maaz

Reputation: 4493

Elasticsearch term facet not showing negative terms

I am using elastic search term facets, My field contains some negative values but the facet is ignoring the negative sign

following is the facet query

http://myserver.com:9200/index/type/_search

Get/Post body

{
  "facets" : {
    "school.id" : {
      "terms" : {
        "field" : "school.id",
        "size" : 10
      }
    }
  }
}

Response

{
    "took": 281,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "facets": {
        "school.id": {
            "_type": "terms",
            "missing": 302,
            "total": 4390,
            "other": 0,
            "terms": [
                {
                    "term": "1113515007867355135",
                    "count": 4390
                }
            ]
        }
    }
}

The actual value of id is -1113515007867355135, am I doing something wrong or do I need to pass anything to include negative sign (stemming issue)?

Upvotes: 2

Views: 1684

Answers (2)

maaz
maaz

Reputation: 4493

Got the answer from Elasticsearch Google Group. Need to update the mapping of the field

Possible Solution:

Update the mapping and use

"index":"analyzed","analyzer" : "keyword"

or

"index": "not_analyzed"

Upvotes: 1

Srikanth Venugopalan
Srikanth Venugopalan

Reputation: 9049

The negative sign is a special character in Lucene (and ElasticSearch).

While indexing and searching you need to escape it.

Try adding a \ before the - character in your index, that should bring it up in the facet as well.

Upvotes: 2

Related Questions