首页 > 解决方案 > Elasticsearch 中的奇怪 Json

问题描述

我正在学习 ELK Stack 进行日志分析,而我无法消化的一件事是,每当我们必须填充索引时,我们必须使用的 JSON 格式并不是真正的 JSON。例如:以下来自于 tutorialspoint 网站,为大量人口填充“学校”类型的“学校”索引:-

{ "index":{ "_index":"schools", "_type":"school", "_id":"1" }}
{"name":"Central School", "description":"CBSE Affiliation", "street":"Nagan","city":"paprola", "state":"HP", "zip":"176115", "location"[31.8955385, 76.8380405],"fees":2000, "tags":["Senior Secondary", "beautiful campus"], "rating":"3.5"}
{ "index":{ "_index":"schools", "_type":"school", "_id":"2" }}
{ "name":"Saint Paul School", "description":"ICSE Afiliation", "street":"Dawarka", "city":"Delhi", "state":"Delhi", "zip":"110075","location":[28.5733056, 77.0122136], "fees":5000,"tags":["Good Faculty", "Great Sports"], "rating":"4.5"}

现在我明白空格是这里的分隔符,并且没有在一行中给出一个实体(索引信息或学校信息),它将返回解析错误。但根据我的理解和这个(供参考),我认为我们确实需要一个顶级密钥下面的学校),上面有一组数据(索引信息和学校信息)的数组([] ) ,可能如下所示:

{"Schools" : [
  {
    {"index":{ "_index":"schools", "_type":"school", "_id":"1" }},
    {"name":"Central School", "description":"CBSE Affiliation", "street":"Nagan","city":"paprola", "state":"HP", "zip":"176115", "location"[31.8955385, 76.8380405],"fees":2000, "tags":["Senior Secondary", "beautiful campus"], "rating":"3.5"}
  },
  {
    { "index":{ "_index":"schools", "_type":"school", "_id":"2" }},
    { "name":"Saint Paul School", "description":"ICSE Afiliation", "street":"Dawarka", "city":"Delhi", "state":"Delhi", "zip":"110075","location":[28.5733056, 77.0122136], "fees":5000,"tags":["Good Faculty", "Great Sports"], "rating":"4.5"}
  }
]}

我还尝试将 POSTMAN 中的有效负载类型从JSON(applicon/json)更改为TEXT,但它返回一个错误,指出需要以前的有效负载。

我显然在这里遗漏了一些东西。如果有人可以推理上述行为,那将非常有帮助。

标签: jsonelasticsearchelastic-stack

解决方案


推荐阅读