我们使用 Logstash 和 Bunyan 在 ElasticSearch 中记录 Restify 请求。但是,当在日志记录中包含 JSON 正文时,索引会发生冲突,因为具有相同名称的字段有时具有不同的类型。
One example is when req.body is sometimes a string and sometimes an object. We've worked around that by always setting body to an object (since our restify API is not supposed to receive strings for any valid requests).
However the problem keeps occurring for fields in the body object. We can't really control what a client sends in, and if a request contains a string where a number is expected the elasticsearch index has already typed that field to number.
Is there any way of continually fixing this apart from checking and potentially replacing every field posted in the body? Converting the body from an object to a string before logging it would work, but that would seriously reduce its usability in Kibana when making visualizations.