Vapor Trail

明るく楽しく元気よく

Bulk Insertした場合のレスポンスをfilter_pathで整形する

Bulk Insertした場合のレスポンスをfilter_pathで整形する

http://localhost:9200/logs/_bulk?filter_path=

",",".","*","-"を駆使して任意の形のレスポンスデータで返ってくるようにできる

  • filter_pathを指定しないでinsertした場合
{
  "took" : 3,
  "errors" : false,
  "items" : [
    {
      "index" : {
        "_index" : "test-2019-05-10",
        "_type" : "_doc",
        "_id" : "4-gXoWoBgMJV7DS8CVGx",
        "_version" : 1,
        "result" : "created",
        "_shards" : {
          "total" : 1,
          "successful" : 1,
          "failed" : 0
        },
        "_seq_no" : 15,
        "_primary_term" : 1,
        "status" : 201
      }
    },
    {
      "index" : {
        "_index" : "test-2019-05-10",
        "_type" : "_doc",
        "_id" : "5OgXoWoBgMJV7DS8CVGx",
        "_version" : 1,
        "result" : "created",
        "_shards" : {
          "total" : 1,
          "successful" : 1,
          "failed" : 0
        },
        "_seq_no" : 13,
        "_primary_term" : 1,
        "status" : 201
      }
    }
  ]
}

?filter_path=took,itemsとすると "errors"を除いたデータが返ってくる

{
  "took" : 3,
  "items" : [
    {
      "index" : {
        "_index" : "test-2019-05-10",
        "_type" : "_doc",
        "_id" : "4-gXoWoBgMJV7DS8CVGx",
        "_version" : 1,
        "result" : "created",
        "_shards" : {
          "total" : 1,
          "successful" : 1,
          "failed" : 0
        },
        "_seq_no" : 15,
        "_primary_term" : 1,
        "status" : 201
      }
    },
    {
      "index" : {
        "_index" : "test-2019-05-10",
        "_type" : "_doc",
        "_id" : "5OgXoWoBgMJV7DS8CVGx",
        "_version" : 1,
        "result" : "created",
        "_shards" : {
          "total" : 1,
          "successful" : 1,
          "failed" : 0
        },
        "_seq_no" : 13,
        "_primary_term" : 1,
        "status" : 201
      }
    }
  ]
}

?filter_path=items.*._shardsとすると

フィールドの階層をワイルドカードで取得できる

{
  "items": [
    {
      "index": {
        "_shards": {
          "total": 1,
          "successful": 1,
          "failed": 0
        }
      }
    },
    {
      "index": {
        "_shards": {
          "total": 1,
          "successful": 1,
          "failed": 0
        }
      }
    }
  ]
}

?filter_path=-itemsとすると
itemsのデータを除外したレスポンスが返ってくる

{"took":5,"errors":false}

www.elastic.co