如何使用Java在弹性搜索中获取特定数据

时间:2019-03-29 11:56:13

标签: java elasticsearch kibana

我需要在弹性搜索数据库的“情感”下获取“数据”字段,如下所示。我能够编写代码以获取情感部分,但不知道如何获取“数据”部分。有人可以向我显示正确的代码吗?

KIBANA结果

"hits": [
  {
    "_index": "local_rs_4_0_0_app_reviewspotter_1552993787904",
    "_type": "review",
    "_id": "r_anuradhapura_1553834187140",
    "_score": 1,
    "_source": {
      "sentiments": [
        {
          "voice": "POSITIVE",
          "referencedChunks": [
            {
              "voice": "NEGATIVE",
              "data": "I’ve always stay here when I come to San Diego",
              "subjects": [],
              "start": 159,
              "weight": -0.5,
              "end": 205,
              "text": "I’ve always stay here when I come to San Diego"
            }
          ],
          "data": " it looks like I will have to find another place.",
          "subjects": [
            {
              "voice": "POSITIVE",
              "fact": "location",
              "effectiveChunk": {
                "start": 219,
                "end": 257
              },
              "data": "location",
              "start": 252,
              "qualities": [
                {
                  "data": "pos_emotion",
                  "strength": "null",
                  "start": 219,
                  "weight": 50,
                  "end": 223,
                  "text": "like",
                  "qualityType": "POSITIVE",
                  "strengthEnd": -1,
                  "strengthStart": -1
                }
              ],
              "weight": 0.5,
              "end": 257,
              "text": "place"
            }
          ],
          "start": 219,
          "weight": 0.5,
          "end": 257,
          "text": "like I will have to find another place"
        }
      ]
    }
  },

Java代码

ArrayList sentimentData = ( ArrayList ) esReader.readAsPairRDD( index, type, "*" ).collect().get( 0 )._2.get( "sentiments" );

0 个答案:

没有答案