从弹性搜索中的索引中删除现有字段
Removing an existing field from an index in Elastic Search
我是 Elastic search 的新手。我的索引中有一个不需要的字段,比如索引名称 "test_index"。这包含近 155154 个文档。我想从我的索引中删除不需要的字段 "B"。这就是我的索引模式在 json 格式
中的样子
{A:{B:{C:}}
我相信删除 B 也会自动从我的索引中删除 C。为此,我使用了以下查询,但它似乎没有用。
POST test_index/_update_by_query?conflicts=proceed {
"script" : "ctx._source.A.remove('B')",
"query" : {
"exists": { "field": "A.B" }
}
}
请让我知道我哪里做错了。
谢谢
你的语法是正确的。你会超时,因为它 运行 在后台运行进程并在 完成任务 之前超时。
您可以 run the query asynchronously 通过指定 wait_for_completion=false
POST test_index/_update_by_query?conflicts=proceed&wait_for_completion=false
{
"script" : "ctx._source.A.remove('B')",
"query" : {
"exists": { "field": "A.B" }
}
}
上面会给出一个带有taskId的响应
{
"task" : "{taskId:node}"
}
现在您可以使用 task api to get the status of the task 使用上面的值
GET _tasks/{taskId:node}
或者,如果您不指定 wait_for_completion=false
并获得超时,您仍然可以通过以下操作获得所有任务。但是,我建议做第一个。
GET _tasks?actions=*byquery&detailed.
From comments: Now say if I have 100 index having a similar name
pattern for example an index having a name "test_date - MM/DD/YYYY"
here the prefix is same "test"
为了处理多个索引,您可以使用通配符语法并将索引名称替换为前缀和 *
例如,下面的查询将对所有以 test
:
开头的索引 运行
POST test*/_update_by_query?conflicts=proceed&wait_for_completion=false
{
"script" : "ctx._source.A.remove('B')",
"query" : {
"exists": { "field": "A.B" }
}
}
我是 Elastic search 的新手。我的索引中有一个不需要的字段,比如索引名称 "test_index"。这包含近 155154 个文档。我想从我的索引中删除不需要的字段 "B"。这就是我的索引模式在 json 格式
中的样子{A:{B:{C:}}
我相信删除 B 也会自动从我的索引中删除 C。为此,我使用了以下查询,但它似乎没有用。
POST test_index/_update_by_query?conflicts=proceed {
"script" : "ctx._source.A.remove('B')",
"query" : {
"exists": { "field": "A.B" }
}
}
请让我知道我哪里做错了。
谢谢
你的语法是正确的。你会超时,因为它 运行 在后台运行进程并在 完成任务 之前超时。
您可以 run the query asynchronously 通过指定 wait_for_completion=false
POST test_index/_update_by_query?conflicts=proceed&wait_for_completion=false
{
"script" : "ctx._source.A.remove('B')",
"query" : {
"exists": { "field": "A.B" }
}
}
上面会给出一个带有taskId的响应
{
"task" : "{taskId:node}"
}
现在您可以使用 task api to get the status of the task 使用上面的值
GET _tasks/{taskId:node}
或者,如果您不指定 wait_for_completion=false
并获得超时,您仍然可以通过以下操作获得所有任务。但是,我建议做第一个。
GET _tasks?actions=*byquery&detailed.
From comments: Now say if I have 100 index having a similar name pattern for example an index having a name "test_date - MM/DD/YYYY" here the prefix is same "test"
为了处理多个索引,您可以使用通配符语法并将索引名称替换为前缀和 *
例如,下面的查询将对所有以 test
:
POST test*/_update_by_query?conflicts=proceed&wait_for_completion=false
{
"script" : "ctx._source.A.remove('B')",
"query" : {
"exists": { "field": "A.B" }
}
}