3

在 Python 项目中,我有一个弹性搜索索引,当我对给定字段进行排序时会引发以下错误:elasticsearch.exceptions.RequestError: RequestError(400, 'search_phase_execution_exception', 'Fielddata is disabled on text fields by default. Set fielddata=true on [my_field] 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.')

最初这是一个文本字段,所以我按照消息的建议进行操作,并尝试将其更改为关键字字段或设置 fielddata=True。不幸的是,这些更改仍然会导致完全相同的错误消息,所以现在我很困惑。

以下是我尝试在文档索引中定义字段的不同方法。所有都会导致相同的错误。

from elasticsearch_dsl import DocType, Index, field, Keyword

class MyDoc(DocType):
    my_field = field.Text(fields={'raw': field.Keyword()})
    my_field = field.Keyword(fielddata=True)
    my_field = field.Keyword()
    my_field = Keyword()
    my_field = Keyword(fields={'raw': field.Keyword()})

我的索引映射:

{
my-index: {
mappings: {
doc: {
properties: {
code: {
type: "text",
fields: {
keyword: {
type: "keyword",
ignore_above: 256
}
}
},
my_field: {
type: "text",
fields: {
keyword: {
type: "keyword",
ignore_above: 256
}
}
}
}
}
}
}
}

我的查询:

{'query': {'bool': {'filter': [{'bool': {'must_not': [{'terms': {'code': []}}]}}]}}, 'sort': ['my_field'], 'from': 0, 'size': 6}
4

0 回答 0