Elasticsearch的初始脚本

时间:2019-01-02 20:52:30

标签: elasticsearch

是否可以为Elasticsearch创建初始脚本?

例如,我准备一个索引为20位用户和20本书的JSON文件。 我想通过单个请求加载它。

示例文件:

PUT eyes
{
    "settings" : {
        "number_of_shards" : 1
    },
    "mappings" : {
        "_doc" : {
            "properties" : {
                "name" : { "type" :  "text" },
                "color" : { "type" : "text" }
            }
        }
    }
}


PUT eyes/_doc/1
{
    "name": "XXX"
  "color" : "red"
}
PUT eyes/_doc/2
{
    "name": "XXXX"
  "color" : "blue"
}

1 个答案:

答案 0 :(得分:0)

您可以使用批量API在一次调用中填充索引。

https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html

my $seq_num = $ARGV[0];
my $dir = '.';
my @matches;

opendir(my $dh, $dir) or die "Can't opendir $dir: $!";
while (my $name = readdir $dh) {
    for my $bp ( @files ) {
        if ( $name =~ /^\Q$bp\E_\d{14}_\Q$seq_num\E\.CSV/ ) {
            push @matches, $bp;
            last;
        }
    }
}
closedir $dh;