{
  "openapi": "3.0.3",
  "info": {
    "title": "Analytics Security Facede",
    "version": "v1",
    "description": ""
  },
  "servers": [
    {
      "url": "https://cloud.kaaiot.com/asf/api/v1",
      "description": "API Server"
    }
  ],
  "paths": {
    "/_ingest/pipeline/{pipelineID}": {
      "parameters": [
        {
          "name": "pipelineID",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Pipeline ID.",
          "example": "application-bspu4tiikfmmfgrk47jg"
        }
      ],
      "put": {
        "description": "Create or update existing ingest pipeline.",
        "responses": {
          "200": {
            "description": "Pipeline is successfully created.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "acknowledged": true
                }
              }
            }
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "application:update"
            ]
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "processors": [
                  {
                    "set": {
                      "if": "ctx.dataSample.tp > 30",
                      "field": "dataSample.temperatureLevel",
                      "value": "HIGH"
                    }
                  },
                  {
                    "set": {
                      "if": "ctx.dataSample.tp >= 0",
                      "field": "dataSample.temperatureLevel",
                      "value": "NORMAL"
                    }
                  },
                  {
                    "set": {
                      "if": "ctx.dataSample.tp < 0",
                      "field": "dataSample.temperatureLevel",
                      "value": "LOW"
                    }
                  },
                  {
                    "script": {
                      "lang": "painless",
                      "source": "ctx['dataSample']['computedValue'] = Math.log(ctx['dataSample']['ozone_sensor'] * 2) + ctx['dataSample']['PM_2_sensor'];"
                    }
                  }
                ]
              }
            }
          }
        }
      },
      "get": {
        "description": "Retrieves pipeline by ID.",
        "responses": {
          "200": {
            "description": "Pipeline is successfully retrieved.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "e02e0679-2de5-48af-a2f0-c650356dc739-application-bspu4tiikfmmfgrk47jg": {
                    "processors": [
                      {
                        "set": {
                          "if": "ctx.dataSample.tp > 30",
                          "field": "dataSample.temperatureLevel",
                          "value": "HIGH"
                        }
                      },
                      {
                        "set": {
                          "if": "ctx.dataSample.tp >= 0",
                          "field": "dataSample.temperatureLevel",
                          "value": "NORMAL"
                        }
                      },
                      {
                        "set": {
                          "if": "ctx.dataSample.tp < 0",
                          "field": "dataSample.temperatureLevel",
                          "value": "LOW"
                        }
                      },
                      {
                        "script": {
                          "lang": "painless",
                          "source": "ctx['dataSample']['computedValue'] = Math.log(ctx['dataSample']['ozone_sensor'] * 2) + ctx['dataSample']['PM_2_sensor'];"
                        }
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "application:read"
            ]
          }
        ]
      },
      "delete": {
        "description": "Deletes pipeline by ID.",
        "responses": {
          "200": {
            "description": "Pipeline is successfully deleted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "acknowledged": true
                }
              }
            }
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "application:delete"
            ]
          }
        ]
      }
    },
    "/_ingest/pipeline/simulate/{pipelineID}": {
      "parameters": [
        {
          "name": "pipelineID",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Pipeline ID.",
          "example": "application-bspu4tiikfmmfgrk47jg"
        }
      ],
      "post": {
        "description": "Simulate pipeline by ID.",
        "responses": {
          "200": {
            "description": "Simulated pipeline result by ID.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "docs": [
                    {
                      "doc": {
                        "_index": "_index",
                        "_type": "_doc",
                        "_id": "_id",
                        "_source": {
                          "@timestamp": "2021-05-26T00:17:08.903Z",
                          "serverTimestamp": 1621988228880,
                          "appName": "bspu4tiikfmmfgrk47jg",
                          "endpointId": "4aae8471-5c7d-499a-9e5b-dafaba23ff66",
                          "@version": "1",
                          "tenantId": "d6312fc1-4c5d-4d1d-8c8c-8ab16435b560",
                          "dataSample": {
                            "computedValue": 540.3868793193626,
                            "ozone_sensor": 297,
                            "nitrogen_dioxide_sensor": 764,
                            "PM_2_sensor": 534,
                            "temperatureLevel": "NORMAL",
                            "PM_10_sensor": 270,
                            "humidity_sensor": 54,
                            "pressure": 828.9828409507737,
                            "air_quality_index": 5,
                            "tp": 11
                          },
                          "appVersionName": "bspu4tiikfmmfgrk47jg-v1"
                        },
                        "_ingest": {
                          "timestamp": "2021-12-13T15:09:15.996099824Z"
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "application:update"
            ]
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "docs": [
                  {
                    "_source": {
                      "appVersionName": "bspu4tiikfmmfgrk47jg-v1",
                      "appName": "bspu4tiikfmmfgrk47jg",
                      "@timestamp": "2021-05-26T00:17:08.903Z",
                      "serverTimestamp": 1621988228880,
                      "dataSample": {
                        "humidity_sensor": 54,
                        "PM_2_sensor": 534,
                        "air_quality_index": 5,
                        "PM_10_sensor": 270,
                        "ozone_sensor": 297,
                        "pressure": 828.9828409507737,
                        "nitrogen_dioxide_sensor": 764,
                        "tp": 11
                      },
                      "@version": "1",
                      "endpointId": "4aae8471-5c7d-499a-9e5b-dafaba23ff66",
                      "tenantId": "d6312fc1-4c5d-4d1d-8c8c-8ab16435b560"
                    }
                  }
                ]
              }
            }
          }
        }
      }
    },
    "/_ingest/pipeline/simulate/": {
      "post": {
        "description": "Simulate pipeline with body data.",
        "responses": {
          "200": {
            "description": "Simulated pipeline result.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "docs": [
                    {
                      "doc": {
                        "_index": "_index",
                        "_type": "_doc",
                        "_id": "_id",
                        "_source": {
                          "@timestamp": "2021-05-26T00:17:08.903Z",
                          "serverTimestamp": 1621988228880,
                          "appName": "bspu4tiikfmmfgrk47jg",
                          "endpointId": "4aae8471-5c7d-499a-9e5b-dafaba23ff66",
                          "@version": "1",
                          "tenantId": "d6312fc1-4c5d-4d1d-8c8c-8ab16435b560",
                          "dataSample": {
                            "computedValue": 540.3868793193626,
                            "ozone_sensor": 297,
                            "nitrogen_dioxide_sensor": 764,
                            "PM_2_sensor": 534,
                            "temperatureLevel": "NORMAL",
                            "PM_10_sensor": 270,
                            "humidity_sensor": 54,
                            "pressure": 828.9828409507737,
                            "air_quality_index": 5,
                            "tp": 11
                          },
                          "appVersionName": "bspu4tiikfmmfgrk47jg-v1"
                        },
                        "_ingest": {
                          "timestamp": "2021-12-13T15:09:15.996099824Z"
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "pipeline": {
                  "processors": [
                    {
                      "set": {
                        "if": "ctx.dataSample.tp > 30",
                        "field": "dataSample.temperatureLevel",
                        "value": "HIGH"
                      }
                    },
                    {
                      "set": {
                        "if": "ctx.dataSample.tp >= 0",
                        "field": "dataSample.temperatureLevel",
                        "value": "NORMAL"
                      }
                    },
                    {
                      "set": {
                        "if": "ctx.dataSample.tp < 0",
                        "field": "dataSample.temperatureLevel",
                        "value": "LOW"
                      }
                    },
                    {
                      "script": {
                        "lang": "painless",
                        "source": "ctx['dataSample']['computedValue'] = Math.log(ctx['dataSample']['ozone_sensor'] * 2) + ctx['dataSample']['PM_2_sensor'];"
                      }
                    }
                  ]
                },
                "docs": [
                  {
                    "_index": "d6312fc1-4c5d-4d1d-8c8c-8ab16435b560-bspu4tiikfmmfgrk47jg-2021.05.26",
                    "_type": "_doc",
                    "_id": "DjoIpnkBs0b6s2dRQFFN",
                    "_score": 10.692778,
                    "_source": {
                      "appVersionName": "bspu4tiikfmmfgrk47jg-v1",
                      "appName": "bspu4tiikfmmfgrk47jg",
                      "@timestamp": "2021-05-26T00:17:08.903Z",
                      "serverTimestamp": 1621988228880,
                      "dataSample": {
                        "humidity_sensor": 54,
                        "PM_2_sensor": 534,
                        "air_quality_index": 5,
                        "PM_10_sensor": 270,
                        "ozone_sensor": 297,
                        "pressure": 828.9828409507737,
                        "nitrogen_dioxide_sensor": 764,
                        "tp": 11
                      },
                      "@version": "1",
                      "endpointId": "4aae8471-5c7d-499a-9e5b-dafaba23ff66",
                      "tenantId": "d6312fc1-4c5d-4d1d-8c8c-8ab16435b560"
                    }
                  }
                ]
              }
            }
          }
        }
      }
    },
    "/{tenantID}-{applicationName}/_template": {
      "put": {
        "description": "Index templates allow to define templates that will automatically be applied to new indices created. The templates include both settings and mappings.",
        "responses": {
          "200": {
            "description": "Template created successfully.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "acknowledged": true
                }
              }
            }
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "application:update"
            ]
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "mappings": {
                  "properties": {
                    "@timestamp": {
                      "type": "date"
                    },
                    "serverTimestamp": {
                      "type": "long"
                    },
                    "appName": {
                      "type": "text",
                      "fields": {
                        "keyword": {
                          "ignore_above": 256,
                          "type": "keyword"
                        }
                      }
                    },
                    "endpointId": {
                      "type": "text",
                      "fields": {
                        "keyword": {
                          "ignore_above": 256,
                          "type": "keyword"
                        }
                      }
                    },
                    "@version": {
                      "type": "text",
                      "fields": {
                        "keyword": {
                          "ignore_above": 256,
                          "type": "keyword"
                        }
                      }
                    },
                    "tenantId": {
                      "type": "text",
                      "fields": {
                        "keyword": {
                          "ignore_above": 256,
                          "type": "keyword"
                        }
                      }
                    },
                    "dataSample": {
                      "properties": {
                        "dv": {
                          "properties": {
                            "st": {
                              "type": "long"
                            },
                            "id": {
                              "type": "long"
                            },
                            "ts": {
                              "type": "text",
                              "fields": {
                                "keyword": {
                                  "ignore_above": 256,
                                  "type": "keyword"
                                }
                              }
                            }
                          }
                        },
                        "ms": {
                          "properties": {
                            "aq": {
                              "type": "long"
                            },
                            "ps": {
                              "properties": {
                                "2": {
                                  "type": "long"
                                },
                                "10": {
                                  "type": "long"
                                }
                              }
                            },
                            "n2": {
                              "type": "long"
                            },
                            "o3": {
                              "type": "long"
                            },
                            "rh": {
                              "type": "long"
                            },
                            "tp": {
                              "type": "long"
                            },
                            "ts": {
                              "type": "date"
                            }
                          }
                        }
                      }
                    },
                    "appVersionName": {
                      "type": "text",
                      "fields": {
                        "keyword": {
                          "ignore_above": 256,
                          "type": "keyword"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "get": {
        "description": "Retrieve template.",
        "responses": {
          "200": {
            "description": "Template retrieved successfully.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "e02e0679-2de5-48af-a2f0-c650356dc739-bspu4tiikfmmfgrk47jg": {
                    "order": 0,
                    "index_patterns": [
                      "e02e0679-2de5-48af-a2f0-c650356dc739-bspu4tiikfmmfgrk47jg-*"
                    ],
                    "settings": {},
                    "mappings": {
                      "properties": {
                        "@timestamp": {
                          "type": "date"
                        },
                        "serverTimestamp": {
                          "type": "long"
                        },
                        "appName": {
                          "type": "text",
                          "fields": {
                            "keyword": {
                              "ignore_above": 256,
                              "type": "keyword"
                            }
                          }
                        },
                        "endpointId": {
                          "type": "text",
                          "fields": {
                            "keyword": {
                              "ignore_above": 256,
                              "type": "keyword"
                            }
                          }
                        },
                        "@version": {
                          "type": "text",
                          "fields": {
                            "keyword": {
                              "ignore_above": 256,
                              "type": "keyword"
                            }
                          }
                        },
                        "tenantId": {
                          "type": "text",
                          "fields": {
                            "keyword": {
                              "ignore_above": 256,
                              "type": "keyword"
                            }
                          }
                        },
                        "dataSample": {
                          "properties": {
                            "dv": {
                              "properties": {
                                "st": {
                                  "type": "long"
                                },
                                "id": {
                                  "type": "long"
                                },
                                "ts": {
                                  "type": "text",
                                  "fields": {
                                    "keyword": {
                                      "ignore_above": 256,
                                      "type": "keyword"
                                    }
                                  }
                                }
                              }
                            },
                            "ms": {
                              "properties": {
                                "aq": {
                                  "type": "long"
                                },
                                "ps": {
                                  "properties": {
                                    "2": {
                                      "type": "long"
                                    },
                                    "10": {
                                      "type": "long"
                                    }
                                  }
                                },
                                "n2": {
                                  "type": "long"
                                },
                                "o3": {
                                  "type": "long"
                                },
                                "rh": {
                                  "type": "long"
                                },
                                "tp": {
                                  "type": "long"
                                },
                                "ts": {
                                  "type": "date"
                                }
                              }
                            }
                          }
                        },
                        "appVersionName": {
                          "type": "text",
                          "fields": {
                            "keyword": {
                              "ignore_above": 256,
                              "type": "keyword"
                            }
                          }
                        }
                      }
                    },
                    "aliases": {}
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "application:read"
            ]
          }
        ]
      }
    },
    "/{tenantID}-{applicationName}/_mapping": {
      "get": {
        "description": null,
        "responses": {
          "200": {
            "description": "Mapping retrieved successfully.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "d6312fc1-4c5d-4d1d-8c8c-8ab16435b560-c1hod7irqa51r8l340ug-2021.07.04": {
                    "mappings": {
                      "properties": {
                        "@timestamp": {
                          "type": "date"
                        },
                        "@version": {
                          "type": "text",
                          "fields": {
                            "keyword": {
                              "type": "keyword",
                              "ignore_above": 256
                            }
                          }
                        },
                        "appName": {
                          "type": "text",
                          "fields": {
                            "keyword": {
                              "type": "keyword",
                              "ignore_above": 256
                            }
                          }
                        },
                        "appVersionName": {
                          "type": "text",
                          "fields": {
                            "keyword": {
                              "type": "keyword",
                              "ignore_above": 256
                            }
                          }
                        },
                        "dataSample": {
                          "properties": {
                            "dv": {
                              "properties": {
                                "id": {
                                  "type": "long"
                                },
                                "st": {
                                  "type": "long"
                                },
                                "ts": {
                                  "type": "text",
                                  "fields": {
                                    "keyword": {
                                      "type": "keyword",
                                      "ignore_above": 256
                                    }
                                  }
                                }
                              }
                            },
                            "ms": {
                              "properties": {
                                "aq": {
                                  "type": "long"
                                },
                                "n2": {
                                  "type": "long"
                                },
                                "o3": {
                                  "type": "long"
                                },
                                "ps": {
                                  "properties": {
                                    "10": {
                                      "type": "long"
                                    },
                                    "2": {
                                      "type": "long"
                                    }
                                  }
                                },
                                "rh": {
                                  "type": "long"
                                },
                                "tp": {
                                  "type": "long"
                                },
                                "ts": {
                                  "type": "date"
                                }
                              }
                            }
                          }
                        },
                        "endpointId": {
                          "type": "text",
                          "fields": {
                            "keyword": {
                              "type": "keyword",
                              "ignore_above": 256
                            }
                          }
                        },
                        "serverTimestamp": {
                          "type": "long"
                        },
                        "tenantId": {
                          "type": "text",
                          "fields": {
                            "keyword": {
                              "type": "keyword",
                              "ignore_above": 256
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "application:read"
            ]
          }
        ]
      }
    },
    "/{tenantID}-kaa-system-traffic-statistics/_search": {
      "post": {
        "description": null,
        "responses": {
          "200": {
            "description": "System traffic statistics retrieved successfully.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "took": 622,
                  "timed_out": false,
                  "_shards": {
                    "total": 2,
                    "successful": 2,
                    "skipped": 0,
                    "failed": 0
                  },
                  "hits": {
                    "total": {
                      "value": 10000,
                      "relation": "gte"
                    },
                    "max_score": null,
                    "hits": []
                  },
                  "aggregations": {
                    "total_size": {
                      "value": 21714555984.0
                    },
                    "last_day": {
                      "buckets": [
                        {
                          "key": "1639267200000-1639421137291",
                          "from": 1639267200000.0,
                          "from_as_string": "1639267200000",
                          "to": 1639421137291.0,
                          "to_as_string": "1639421137291",
                          "doc_count": 51003,
                          "total_size": {
                            "value": 227546370.0
                          }
                        }
                      ]
                    },
                    "last_week": {
                      "buckets": [
                        {
                          "key": "1638748800000-1639421137291",
                          "from": 1638748800000.0,
                          "from_as_string": "1638748800000",
                          "to": 1639421137291.0,
                          "to_as_string": "1639421137291",
                          "doc_count": 224638,
                          "total_size": {
                            "value": 1007014961.0
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "traffic-statistic:read"
            ]
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "size": 0,
                "aggs": {
                  "last_day": {
                    "date_range": {
                      "field": "timeFrom",
                      "ranges": [
                        {
                          "from": "now-1d/d",
                          "to": "now"
                        }
                      ]
                    },
                    "aggs": {
                      "total_size": {
                        "sum": {
                          "field": "receivedPayload",
                          "missing": 0
                        }
                      }
                    }
                  },
                  "last_week": {
                    "date_range": {
                      "field": "timeFrom",
                      "ranges": [
                        {
                          "from": "now-1w/w",
                          "to": "now"
                        }
                      ]
                    },
                    "aggs": {
                      "total_size": {
                        "sum": {
                          "field": "receivedPayload",
                          "missing": 0
                        }
                      }
                    }
                  },
                  "total_size": {
                    "sum": {
                      "field": "receivedPayload",
                      "missing": 0
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/{tenantID}-{applicationName}-{date}/_search": {
      "post": {
        "description": "Search documents.",
        "responses": {
          "200": {
            "description": "Successfully made search request.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "took": 652,
                  "timed_out": false,
                  "_shards": {
                    "total": 2,
                    "successful": 2,
                    "skipped": 0,
                    "failed": 0
                  },
                  "hits": {
                    "total": {
                      "value": 10000,
                      "relation": "gte"
                    },
                    "max_score": null,
                    "hits": []
                  },
                  "aggregations": {
                    "total_size": {
                      "value": 21793173173.0
                    },
                    "last_day": {
                      "buckets": [
                        {
                          "key": "1639353600000-1639475966058",
                          "from": 1639353600000.0,
                          "from_as_string": "1639353600000",
                          "to": 1639475966058.0,
                          "to_as_string": "1639475966058",
                          "doc_count": 40559,
                          "total_size": {
                            "value": 179012705.0
                          }
                        }
                      ]
                    },
                    "last_week": {
                      "buckets": [
                        {
                          "key": "1638748800000-1639475966058",
                          "from": 1638748800000.0,
                          "from_as_string": "1638748800000",
                          "to": 1639475966058.0,
                          "to_as_string": "1639475966058",
                          "doc_count": 242845,
                          "total_size": {
                            "value": 1085632150.0
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        },
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "size": 0,
                "aggs": {
                  "last_day": {
                    "date_range": {
                      "field": "timeFrom",
                      "ranges": [
                        {
                          "from": "now-1d/d",
                          "to": "now"
                        }
                      ]
                    },
                    "aggs": {
                      "total_size": {
                        "sum": {
                          "field": "receivedPayload",
                          "missing": 0
                        }
                      }
                    }
                  },
                  "last_week": {
                    "date_range": {
                      "field": "timeFrom",
                      "ranges": [
                        {
                          "from": "now-1w/w",
                          "to": "now"
                        }
                      ]
                    },
                    "aggs": {
                      "total_size": {
                        "sum": {
                          "field": "receivedPayload",
                          "missing": 0
                        }
                      }
                    }
                  },
                  "total_size": {
                    "sum": {
                      "field": "receivedPayload",
                      "missing": 0
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/{tenantID}-{applicationName}-{date}/_msearch": {
      "post": {
        "description": "The multi search API allows to execute several search requests within the same API.",
        "responses": {
          "200": {
            "description": "Successfully made msearch request.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "took": 652,
                  "timed_out": false,
                  "_shards": {
                    "total": 2,
                    "successful": 2,
                    "skipped": 0,
                    "failed": 0
                  },
                  "hits": {
                    "total": {
                      "value": 10000,
                      "relation": "gte"
                    },
                    "max_score": null,
                    "hits": []
                  }
                }
              }
            }
          }
        },
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "query": {
                  "match": {
                    "message": "this is a test"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "oauth_2_0": {
        "type": "oauth2",
        "description": "Analytics Security Facede supports OAuth 2.0 for authenticating all API requests.\n",
        "flows": {
          "implicit": {
            "authorizationUrl": "https://auth.example.com/oauth/authorize",
            "scopes": {}
          }
        }
      }
    },
    "schemas": {}
  }
}