是否根据查询创建新的ElasticSearch索引?

lyr7nygr  于 2022-12-22  发布在  ElasticSearch
关注(0)|答案(2)|浏览(97)

SQL有“INSERT INTO... SELECT”语句来用查询中的数据填充表。Elasticsearch有这样的语句吗?
这将阻止我使用查询从现有索引中大量删除数据-这是官方的Elasticsearch 2.1指南警告的:
不要使用delete-by-query来清除索引中的所有或大部分文档,而是创建一个新的索引,也许可以重新索引您想要保留的文档。
(来源:https://www.elastic.co/guide/en/elasticsearch/plugins/current/plugins-delete-by-query.html)。

nafvub8i

nafvub8i1#

您可以使用taskrabbit中名为elasticdump的优秀实用程序。
有很多选项可以定制导入过程,在您的情况下,我将使用searchBody选项,并使用如下内容:

elasticdump \
  --input=http://HOST:9200/source_index \
  --output=http://HOST:9200/target_index \
  --bulk=true \
  --searchBody='{"query": { "match_all": {} } }'

您可以自定义查询,只有source_index中的匹配文档才会复制到target_index

kyvafyod

kyvafyod2#

看看创建索引API:https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html

PUT /test
{
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
    "properties": {
      "field1": { "type": "text" }
    }
  }
}

相关问题