Elasticsearch aggregation issue with "Filter"

Elasticsearch aggregation issue with "Filter", With "Filter" missing field and alphabetical sorting with lower and uppercase not working

Below is the sol for sorting.

PUT my_index1
{
   "settings": {
      "analysis": {
         "analyzer": {
            "analyzer_keyword": {
               "filter": "lowercase",
               "tokenizer": "keyword"
            }
         }
      }
   },
   "mappings": {
      "type": {
         "properties": {
            "name": {
               "type": "string",
               "fields": {
                  "sort": {
                     "type": "string",
                     "analyzer": "analyzer_keyword",
                     "fielddata": true
                  },
                  "not_ana": {
                     "type": "string",
                     "index": "not_analyzed"
                  }
               }
            }
         }
      }
   }
}

PUT /my_index1/type/_bulk
{"index":{"_id":1}}
{"name":"Boffey"}
{"index":{"_id":2}}
{"name":"BROWN"}
{"index":{"_id":3}}
{"name":"bailey"}
{"index":{"_id":4}}
{"name":"Böhm"}
{"index":{"_id":5}}
{"name":"bp"}
{"index":{"_id":6}}
{"name":"animal"}
{"index":{"_id":7}}
{"name":"Ample"}
{"index":{"_id":8}}
{"name":"category"}
{"index":{"_id":9}}
{"name":null}

POST /my_index1/type/_search
{
   "size" : 0,
   "aggs": {
      "result": {
         "terms": {
            "field": "name.sort",
            "missing" : "Not Available",
            "order": {
               "_term": "asc"
            }
         },
         "aggs": { 
            "sub_result": { 
               "terms": {
                  "field": "name.not_ana" 
               }
            }
         }
      }
   }
}

Response:
{
   "took": 0,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 12,
      "max_score": 0,
      "hits": []
   },
   "aggregations": {
      "result": {
         "doc_count_error_upper_bound": 0,
         "sum_other_doc_count": 0,
         "buckets": [
            {
               "key": "Not Available",
               "doc_count": 1,
               "sub_result": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": []
               }
            },
            {
               "key": "ample",
               "doc_count": 1,
               "sub_result": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                     {
                        "key": "Ample",
                        "doc_count": 1
                     }
                  ]
               }
            },
            {
               "key": "animal",
               "doc_count": 1,
               "sub_result": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                     {
                        "key": "animal",
                        "doc_count": 1
                     }
                  ]
               }
            },
            {
               "key": "bailey",
               "doc_count": 2,
               "sub_result": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                     {
                        "key": "bailey",
                        "doc_count": 2
                     }
                  ]
               }
            },
            {
               "key": "boffey",
               "doc_count": 2,
               "sub_result": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                     {
                        "key": "Boffey",
                        "doc_count": 2
                     }
                  ]
               }
            },
            {
               "key": "bp",
               "doc_count": 1,
               "sub_result": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                     {
                        "key": "bp",
                        "doc_count": 1
                     }
                  ]
               }
            },
            {
               "key": "brown",
               "doc_count": 2,
               "sub_result": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                     {
                        "key": "BROWN",
                        "doc_count": 2
                     }
                  ]
               }
            },
            {
               "key": "böhm",
               "doc_count": 1,
               "sub_result": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                     {
                        "key": "Böhm",
                        "doc_count": 1
                     }
                  ]
               }
            },
            {
               "key": "category",
               "doc_count": 1,
               "sub_result": {
                  "doc_count_error_upper_bound": 0,
                  "sum_other_doc_count": 0,
                  "buckets": [
                     {
                        "key": "category",
                        "doc_count": 1
                     }
                  ]
               }
            }
         ]
      }
   }
}

But when i add "filter" its not working as expected, missing field not working. Below is the changed query.

POST /my_index1/type/_search
{
   "size": 0,
   "aggs": {
      "result": {
         "filter": {
            "bool": {
               "must": [
                  {
                     "range": {
                        "name.sort": {
                           "from": "ample",
                           "to": null,
                           "include_lower": false,
                           "include_upper": true,
                           "boost": 1
                        }
                     }
                  }
               ],
               "disable_coord": false,
               "adjust_pure_negative": true,
               "boost": 1
            }
         },
         "aggs": {
            "result": {
               "terms": {
                  "field": "name.sort",
                  "order": {
                     "_term": "asc"
                  }
               },
               "aggs": {
                  "sub_result": {
                     "terms": {
                        "field": "name.not_ana"
                     }
                  }
               }
            }
         }
      }
   }
}

Can somebody help me am I doing anything wrong in query while adding filter?

Could not post entire thing in single topic so adding response here for last query in above post. Filtering is working but "missing" field count is missing.

{
   "took": 1,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 12,
      "max_score": 0,
      "hits": []
   },
   "aggregations": {
      "result": {
         "doc_count": 10,
         "result": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
               {
                  "key": "animal",
                  "doc_count": 1,
                  "sub_result": {
                     "doc_count_error_upper_bound": 0,
                     "sum_other_doc_count": 0,
                     "buckets": [
                        {
                           "key": "animal",
                           "doc_count": 1
                        }
                     ]
                  }
               },
               {
                  "key": "bailey",
                  "doc_count": 2,
                  "sub_result": {
                     "doc_count_error_upper_bound": 0,
                     "sum_other_doc_count": 0,
                     "buckets": [
                        {
                           "key": "bailey",
                           "doc_count": 2
                        }
                     ]
                  }
               },
               {
                  "key": "boffey",
                  "doc_count": 2,
                  "sub_result": {
                     "doc_count_error_upper_bound": 0,
                     "sum_other_doc_count": 0,
                     "buckets": [
                        {
                           "key": "Boffey",
                           "doc_count": 2
                        }
                     ]
                  }
               },
               {
                  "key": "bp",
                  "doc_count": 1,
                  "sub_result": {
                     "doc_count_error_upper_bound": 0,
                     "sum_other_doc_count": 0,
                     "buckets": [
                        {
                           "key": "bp",
                           "doc_count": 1
                        }
                     ]
                  }
               },
               {
                  "key": "brown",
                  "doc_count": 2,
                  "sub_result": {
                     "doc_count_error_upper_bound": 0,
                     "sum_other_doc_count": 0,
                     "buckets": [
                        {
                           "key": "BROWN",
                           "doc_count": 2
                        }
                     ]
                  }
               },
               {
                  "key": "böhm",
                  "doc_count": 1,
                  "sub_result": {
                     "doc_count_error_upper_bound": 0,
                     "sum_other_doc_count": 0,
                     "buckets": [
                        {
                           "key": "Böhm",
                           "doc_count": 1
                        }
                     ]
                  }
               },
               {
                  "key": "category",
                  "doc_count": 1,
                  "sub_result": {
                     "doc_count_error_upper_bound": 0,
                     "sum_other_doc_count": 0,
                     "buckets": [
                        {
                           "key": "category",
                           "doc_count": 1
                        }
                     ]
                  }
               }
            ]
         }
      }
   }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.