Subburaj
Subburaj

Reputation: 5192

elasticsearch aggregation result is 0

The following is my query for elasticsearch:

GET index/_search
{
   "size": 0,
   "query": {
      "filtered": {
         "query": {
            "match_all": {}
         },
         "filter": {
            "and": [
               {
                  "term": {
                     "id_1": "xx"
                  }
               },
               {
                  "term": {
                     "level": "level2"
                  }
               },
               {
                  "or": [
                     {
                        "term": {
                           "type": "yyy"
                        }
                     },
                     {
                        "term": {
                           "type": "zzzz"
                        }
                     }
                  ]
               }
            ]
         }
      }
   },
   "aggs": {
      "variable": {
         "stats": {
            "field": "score"
         }
      }
   }
}

But the agg result is as follows:

{
   "took": 2,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 68,
      "max_score": 0,
      "hits": []
   },
   "aggregations": {
      "variable": {
         "count": 30,
         "min": 0,
         "max": 0,
         "avg": 0,
         "sum": 0
      }
   }
}

Why the min,max etc are 0. But value is there for score like(0.18,0.25,etc..). Also in mapping the type for score is long. Please help me to solve this. Thanks in advance.

Edit:

value in index:

"score": 0.18

Single document:

{
            "_index": "index",
            "_type": "ppppp",
            "_id": "n0IiTEd2QFCnJUZOSiNu1w",
            "_score": 1,
            "_source": {
               "name_2": "aaa",
               "keyid": "bbbb",
               "qqq": "cccc",
               "level": "level2",
               "type": "kkk",
               "keytype": "Year",
               "org_id": 25,
               "tempid": "113",
               "id_2": "561",
               "name_1": "xxxxx",
               "date_obj": [
                  {
                     "keyid": "wwwww",
                     "keytype": "Year",
                     "value": 21.510617952000004,
                     "date": "2015",
                     "id": "ggggggg",
                     "productid": ""
                  },
                  {
                     "keyid": "rrrrrr",
                     "keytype": "Year",
                     "value": 0.13,
                     "date": "2015",
                     "id": "iiiiii",
                     "productid": ""
                  }
               ],
               "date": "2015",
               "ddddd": 21.510617952000004,
               "id_1": "29",
               "leveltype": "nnnn",
               "tttt": 0.13,
               "score": 0.13    ------------------->problem           
            }
         }

Mapping:

curl -XPUT ip:9200/index -d '{   
    "mappings" : {
        "places" : {            
            "properties" : {
                "score" : { "type" : "float"}                
            }
        }
}
}'

Upvotes: 0

Views: 196

Answers (1)

Val
Val

Reputation: 217254

The fix should be as simple as changing the type of the score field to float (or double) instead of long. long is an integer type and 0.18 will be indexed as 0 under the hood.

"score" : {
    "type" : "float",
    "null_value" : 0.0
}

Note that you'll need to reindex your data after making the mapping change.

Upvotes: 1

Related Questions