• elasticsearch bulk操作


    Elasticsearch Bulk Index JSON Data
    
    
    我想尝试 buld index 一个json文件到一个新的Elasticsearch index 但是不能这么做,我有下面的json数据
    
    
    [{"Amount": "480", "Quantity": "2", "Id": "975463711", "Client_Store_sk": "1109"},
    {"Amount": "2105", "Quantity": "2", "Id": "975463943", "Client_Store_sk": "1109"},
    {"Amount": "2107", "Quantity": "3", "Id": "974920111", "Client_Store_sk": "1109"},
    {"Amount": "2115", "Quantity": "2", "Id": "975463798", "Client_Store_sk": "1109"},
    {"Amount": "2116", "Quantity": "1", "Id": "975463827", "Client_Store_sk": "1109"},
    {"Amount": "648", "Quantity": "3", "Id": "975464139", "Client_Store_sk": "1109"},
    {"Amount": "2126", "Quantity": "2", "Id": "975464805", "Client_Store_sk": "1109"},
    {"Amount": "2133", "Quantity": "1", "Id": "975464061", "Client_Store_sk": "1109"},
    {"Amount": "1339", "Quantity": "4", "Id": "974919458", "Client_Store_sk": "1109"},
    {"Amount": "1196", "Quantity": "5", "Id": "974920538", "Client_Store_sk": "1109"},
    {"Amount": "1198", "Quantity": "4", "Id": "975463638", "Client_Store_sk": "1109"},
    {"Amount": "1345", "Quantity": "4", "Id": "974919522", "Client_Store_sk": "1109"},
    {"Amount": "1347", "Quantity": "2", "Id": "974919563", "Client_Store_sk": "1109"},
    {"Amount": "673", "Quantity": "2", "Id": "975464359", "Client_Store_sk": "1109"},
    {"Amount": "2153", "Quantity": "1", "Id": "975464511", "Client_Store_sk": "1109"},
    {"Amount": "3896", "Quantity": "4", "Id": "977289342", "Client_Store_sk": "1109"},
    {"Amount": "3897", "Quantity": "4", "Id": "974920602", "Client_Store_sk": "1109"}]
    
    
    
    当我尝试使用标准的buld index api 从elasticseach 我得到了这个错误
    
    {"message":"ActionRequestValidationException[Validation Failed: 1: no requests added;]"}
    
    
    你需要做的是读取那个JSON文件,创建一个bulk 请求格式的
    
    
    即一行用于命令和一行用于文档,用换行符隔开,重复每个文档
    
    curl -XPOST localhost:9200/your_index/_bulk -d '
    {"index": {"_index": "your_index", "_type": "your_type", "_id": "975463711"}}
    {"Amount": "480", "Quantity": "2", "Id": "975463711", "Client_Store_sk": "1109"}
    {"index": {"_index": "your_index", "_type": "your_type", "_id": "975463943"}}
    {"Amount": "2105", "Quantity": "2", "Id": "975463943", "Client_Store_sk": "1109"}
    ... etc for all your documents
    '
    
    
    curl -X POST $elasticsearchwebaddress/_bulk -d '
    { "delete": { "_index": "website", "_type": "blog", "_id": "123" }} 
    { "create": { "_index": "website", "_type": "blog", "_id": "123" }}
    { "title":    "My first blog post" }
    { "index":  { "_index": "website", "_type": "blog" }}
    { "title":    "My second blog post" }
    { "update": { "_index": "website", "_type": "blog", "_id": "123", "_retry_on_conflict" : 3} }
    { "doc" : {"title" : "My updated blog post"} }
    '
    
    
    一行用于命令行,一行用于文档,用换行分开
    
    
    
    
    
    
    

  • 相关阅读:
    A*算法实现 八数码问题
    poj 1077 Eight(bfs,dbfs, A*)
    poj 1729 Jack and Jill (搜索,bfs)
    poj 4105 拯救公主(bfs)
    poj4091The Closest M Points(KD-tree)
    资源整理
    推荐 VS2010入门教程—鸡啄米
    Cstring的使用
    VC 中TEXT、_T、L的区别
    电脑内存和CPU的关系
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349895.html
Copyright © 2020-2023  润新知