0
votes

Using an aggregation function for removing duplicates of a query, I get the following error using the elastics search python lib:

elasticsearch.exceptions.RequestError: TransportError(400, 'search_phase_execution_exception', 'Fielddata is disabled on text fields by default. Set fielddata=true on [uuid] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.')

But as suggested I already recreated the index using a keyword field for "uuid". Here's my mapping:

In [46]: mapping = {
    ...:     'mappings': {
    ...:         'article': {
    ...:          'properties': {
    ...:             'publish_at': {
    ...:                 'type': 'date'
    ...:             },
    ...:             'uuid': {
    ...:                 'type': 'text',
    ...:                 'fields': {
    ...:                     'keyword': {
    ...:                         'type': 'keyword'
    ...:                     }
    ...:                 }
    ...:             }
    ...: }
    ...:         }
    ...:     }
    ...: }

The query I do looks like this:

es_body = {
      'from' : self.limit_from,
                'size' : 10,
                'query': {
                    'bool': {
                        'must': {
                            'multi_match': {
                                'query': keywords,
                                'type':'best_fields',
                                'operator':'and',
                                'fields': [
                                    'title','summary','keywords'
                                ],
                            },
                        },
                        'filter': {
                            'term': {
                                'bot_id': self.current_bot.id
                            }
                        }
                    },
                },
                'aggs': {
                    'unique_uuids': {
                        'terms': {
                            'field': 'uuid'
                        }
                    }
                }        
            }

Any advice on this?

1

1 Answers

1
votes

You are stating in your mapping that uuid is a text entry with a field which will be called uuid.keyword of type keyword. Therefore just change the field you use in the term query to uuid.keyword and this should work.