0

我正在尝试将字符串数组转换为常规字符串。但是使用我的规范文件,它总是作为数组返回

样本输入(来自 ES)

{
    ...
    "hits": {
        "total": 1,
        "max_score": 1.4818809,
        "hits": [
            {
                "_index": "twitter",
                "_type": "tweet",
                "_id": "1",
                "_score": 1.4818809,
                "_source": {
                    "user": "test",
                    "message": "some message with the number 1",
                    "date": "2009-11-15T14:12:12",
                    "likes": 1
                },
                "highlight": {
                    "message": [
                        "some message with the <em>number</em> <em>1</em>"
                    ]
                }
            }
        ]
    }
}

规格文件

[
  {
    "operation": "shift",
    "spec": {
      "took": "took",
      "hits": {
        "total": "total_hits",
        "hits": {
          "*": {
            "_source": {
              "user": "Response[&2].firstName"
            },
            "highlight": {
              "message": ["Response[&2].h_message"]
            }
          }
        }
      }
    }
}
]

输出:

{
  "Response" : [ {
    "firstName" : "test",
    "h_message" : [ "some message with the <em>number</em> <em>1</em>" ]
  } ],
  "total_hits" : 1
}

如您所见,“h_message”以数组形式出现。我试图获取的是字符串/值

 "h_message" : [ "some message with the <em>number</em> <em>1</em>" ]
4

1 回答 1

0

解决了

[
  {
    "operation": "shift",
    "spec": {
      "took": "took",
      "hits": {
        "total": "total_hits",
        "hits": {
          "*": {
            "_source": {
              "user": "Response[&2].firstName"
            },
            "highlight": {
              "message": {
                "*": "Response[&0].h_message"
              }
            }
          }
        }
      }
    }
}
]
于 2017-07-19T21:17:41.413 回答