【发布时间】:2021-02-19 03:42:45
【问题描述】:
我正在编写一个 python 脚本来获取弹性搜索索引中的唯一值。我正在使用术语聚合来获取唯一值及其计数。但是,当我将字段列表传递给脚本时,我意识到某些字段存储为
"abc" : {
"type" : "keyword"
}
有些存储为
"xyz" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword"
}
}
}
在术语聚合期间,我使用查询
{
"aggs" : {
"abc" : {
"terms" : {
"field" : "abc"
}
}
}, "size":0
}
但是当这个查询用于“xyz”时,它会给出错误Fielddata is disabled on text fields by default. Set fielddata=true on [description] 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.
要运行“xyz”查询,我需要向其中添加“.keyword”,但“abc”将不会运行。
有什么方法可以检查哪个字段属于哪个类型,然后使用 if/else 相应地更新查询?
【问题讨论】:
标签: python sql elasticsearch kibana elk