PHP Json 转换的问题

我在使用 kibana 时编写的DSL是能够正常执行查询的。


image.png

DSL 如下:

GET /yourIndex/_search
{
  "size": 0, 
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}
        },
        {
          "range": {
            "@timestamp": {
              "gte": 1564527359490,
              "lte": 1564527359500,
              "format": "epoch_millis"
            }
          }
        }
      ]
    }
  }
}

然后,我就把查询语句放到程序中,执行查询,仍然是正常执行的,示例代码:


image.png

在实际使用过程中,为了方便操作,我把 $info 这个json字符串改为数组格式,在查询时再转换,例如这样:

image.png

于是,问题就来了,Elasticsearch 给我响应的信息如下:

{
    "error": {
      "root_cause": [
        {
          "type": "parsing_exception",
          "reason": "[match_all] query malformed, no start_object after query name",
          "line": 1,
          "col": 49
        }
      ],
      "type": "parsing_exception",
      "reason": "[match_all] query malformed, no start_object after query name",
      "line": 1,
      "col": 49
    },
    "status": 400
  }

什么???match_all 的格式有问题吗?于是,我将原始的 json 字符串,和 经过PHP json_encode() 之后返回的 json 字符串进行对比,结果如下:

image.png

顺便贴一下上图右边PHP处理的方式:


image.png

嗯,今天就写到这。

你可能感兴趣的:(PHP Json 转换的问题)