0

I have a document with a nested object field, called category. Inside category it stores the name of the category and also the name of the parent category where applicable. I'm doing an aggregation to group transactions by their category. The issue I'm having is that ES is returning what seems to be the "analyzed" version of category.name. It's returning "clothing", when the actual name is "Clothing". How can I get ES to return the actual thing I stored. Also, is this the best approach? In my relational database I have a primary key associated with the category, should I store that in ES too.

For reference, here's the query I'm submitting.

// Search for the string "lees" and add grouping by category.name
{'aggs': {'group_by_category': {'terms': {'field': 'category.name'}}},
 'query': {'match': {'description': {'fuzziness': 2, 'query': 'lees'}}}}

And this is the response.

{'_shards': {'failed': 0, 'skipped': 0, 'successful': 1, 'total': 1},
 'aggregations': {'group_by_category': {'buckets': [{'doc_count': 1,
                                                     'key': 'clothing'}],
                                        'doc_count_error_upper_bound': 0,
                                        'sum_other_doc_count': 0}},
 'hits': {'hits': [{'_id': '4',
                    '_index': 'transactions',
                    '_score': 0.2876821,
                    '_source': {'account': {'name': 'Primary'},
                                'amount': 9800.0,
                                'category': {'name': 'Clothing',
                                             'parent': None},
                                'created_by': 'someuser',
                                'date': '2018-02-05',
                                'description': 'Lees',
                                'title': 'Shoes',
                                'title_suggest': 'Shoes'},
                    '_type': 'transaction_document'}],
          'max_score': 0.2876821,
          'total': 1},
 'timed_out': False,
 'took': 1}
jaywhy13
  • 1,068
  • 12
  • 16
  • Can you show your mapping as well? – Val Mar 09 '18 at 06:43
  • Possible duplicate of [Elasticsearch aggregation turns results to lowercase](https://stackoverflow.com/questions/32649217/elasticsearch-aggregation-turns-results-to-lowercase) – Pierre Mallet Mar 09 '18 at 09:42

0 Answers0