【问题标题】:Keyword field not used?关键字字段未使用?
【发布时间】:2018-01-19 03:05:30
【问题描述】:

使用聚合函数删除查询的重复项,使用 elastics search python lib 时出现以下错误:

elasticsearch.exceptions.RequestError: TransportError(400, 'search_phase_execution_exception', 'Fielddata 在文本上被禁用 默认情况下的字段。在 [uuid] 上设置 fielddata=true 以加载 fielddata 在内存中通过反转倒排索引。请注意,这 但是可以使用大量内存。或者使用关键字字段 ')

但正如建议的那样,我已经使用“uuid”的关键字字段重新创建了索引。这是我的映射:

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

我做的查询是这样的:

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'
                        }
                    }
                }        
            }

对此有何建议?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您在映射中声明uuid 是一个文本条目,其字段将被称为uuid.keyword 类型的关键字。因此,只需将您在术语查询中使用的字段更改为 uuid.keyword 即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-22
      • 1970-01-01
      • 1970-01-01
      • 2015-12-01
      • 1970-01-01
      • 2021-07-11
      • 2011-07-26
      • 2020-03-15
      相关资源
      最近更新 更多