我有一些具有以下格式的弹性搜索条目:
{
"_index": "sample_index",
"_type": "documents",
"_id": "SAMPLE-ID",
"_version": 5,
"_source": {
"users": {
"usernames": [
[
"username-1",
"username-2",
"username-3"
],
[
"username-4",
"username-5",
"username-6"
]
]
}
}
}
我想合并usernames
的子数组并将其保存为:
{
"_index": "sample_index",
"_type": "documents",
"_id": "SAMPLE-ID",
"_version": 5,
"_source": {
"users": {
"usernames": [
"username-1",
"username-2",
"username-3",
"username-4",
"username-5",
"username-6"
]
}
}
}
到目前为止,我已经尝试使用以下方法获取所有至少包含一个username
的文档(可能甚至没有users
字段的文档):
GET sample_index/documents/_search
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "users",
"query": {
"exists": {
"field": "users.usernames[0]"
}
}
}
}
]
}
}
}
但这似乎不起作用。
我是Elasticsearch的新手。请帮忙。