首页 文章

关键字字段未使用?

提问于
浏览
0

使用聚合函数删除查询的重复项,使用弹性搜索python库得到以下错误:

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

有什么建议吗?

1 回答

  • 0

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

相关问题