使用Kibana和Java获取弹性搜索中的特定字段

时间:2019-03-22 03:14:49

标签: java sql elasticsearch kibana

我对ELK堆栈非常陌生。我正在尝试检索特定字段(例如在MySQL中,我们认为有一个名为“ Users”的表,试图检索“ phoneNumber”列)。我需要使用Java以及使用在Kibana中键入的查询来做到这一点。 (例如,假设我们需要在弹性搜索数据库中检索字段注释)。谢谢您的帮助。我是Stack Overflow的新手。因此,如果我在提出问题时做错了事,请告诉我,请改正。以下是通过键入在kibana中获得的结果,

POST local_rs_4_0_0_app_test_1552993787904/_search
{
  "query": {
    "match_all": {}
  }
}

{
  "took": 2,
  "timed_out": false,
  "_shards": {
  "total": 3,
  "successful": 3,
  "failed": 0
},
  "hits": {
  "total": 16,
  "max_score": 1,
  "hits": [
    {
    "_index": "local_rs_4_0_0_app_test_1552993787904",
    "_type": "reviewmodel",
    "_id": "rm_apptest1552993787904_hotel",
    "_score": 1,
    "_source": {
      "modelVersion": "RS_4_0_0",
      "appKey": "app_test_1552993787904",
      "entityType": "hotel",
      "reviewParameters": {
        "0": {
          "key": "title",
          "description": "Title",
          "writeEnabled": true,
          "readEnabled": true,
          "usedAsMetadata": false
        },
        "1": {
          "key": "overall",
          "description": "Overall",
          "writeEnabled": true,
          "readEnabled": true,
          "usedAsMetadata": false
        },
        "2": {
          "key": "comment",
          "description": "Comment",
          "writeEnabled": true,
          "readEnabled": true,
          "usedAsMetadata": false
        },
        "3": {
          "key": "country",
          "description": "Country",
          "writeEnabled": true,
          "readEnabled": true,
          "usedAsMetadata": true
        }
      },
      "supportedOntoClass": "hotel"
    }
  },
  {
    "_index": "local_rs_4_0_0_app_test_1552993787904",
    "_type": "formtemplate",
    "_id": "AWmVrLRfjVbLQiy9v6fG",
    "_score": 1,
    "_source": {
      "modelVersion": "RS_4_0_0",
      "templateId": "ft_apptest1552993787904_hotel_hotelcopy1",
      "templateName": "hotel Copy 1",
      "createdUser": "usr_2012187654",
      "createdTime": 1552994317403,
      "formDescription": "",
      "thankYouNote": "Thank You",
      "formHeaderImage": "",
      "lastModifiedUser": "usr_2012187654",
      "lastModifiedTime": 1552994349085,
      "appKey": "app_test_1552993787904",
      "entityType": "hotel",
      "apiCall": null,
      "entityMappedApiCall": null,
      "embeddableScript": null,
      "deleted": true,
      "defaultFormTemplate": false,
      "defaultAttachableFormTemplate": false,
      "mappedViewTemplateKey": "vt_apptest1552993787904_hotel_hotelcopy1",
      "components": {
        "0": {
          "cmpId": "title1552994317403",
          "component": "TEXT_FIELD",
          "parameterKey": "title",
          "required": true,
          "label": "Review Title",
          "description": null,
          "attributes": [],
          "options": [],
          "publicViewVisible": true
        },
        "1": {
          "cmpId": "overall1552994317403",
          "component": "STAR_INPUT",
          "parameterKey": "overall",
          "required": true,
          "label": "Overall Rating",
          "description": null,
          "attributes": [],
          "options": [],
          "publicViewVisible": true
        },
        "2": {
          "cmpId": "comment1552994317403",
          "component": "TEXT_AREA",
          "parameterKey": "comment",
          "required": true,
          "label": "Comment",
          "description": null,
          "attributes": [],
          "options": [],
          "publicViewVisible": true
        },
        "3": {
          "cmpId": "country1552994317403",
          "component": "COUNTRY_PICKER",
          "parameterKey": "country",
          "required": false,
          "label": "Country",
          "description": null,
          "attributes": [],
          "options": [],
          "publicViewVisible": true
        }
      },
      "embeddedEntities": [],
      "groups": []
    }
  },
  {
    "_index": "local_rs_4_0_0_app_test_1552993787904",
    "_type": "viewtemplate",
    "_id": "AWmVrLTZjVbLQiy9v6fH",
    "_score": 1,
    "_source": {
      "modelVersion": "RS_4_0_0",
      "templateId": "vt_apptest1552993787904_hotel_hotelcopy1",
      "templateName": "hotel Copy 1",
      "appKey": "app_reviewspotter_1552993787904",
      "entityType": "hotel",
      "createdUser": "usr_2012187654",
      "createdTime": 1552994317527,
      "lastModifiedUser": "usr_2012187654",
      "lastModifiedTime": 1552994349270,
      "components": {
        "0": {
          "parameterKey": "title",
          "component": "TEXT_VIEW",
          "label": "Review Title",
          "publicViewVisible": true
        },
        "1": {
          "parameterKey": "overall",
          "component": "STAR_VIEW",
          "label": "Overall Rating",
          "publicViewVisible": true
        },
        "2": {
          "parameterKey": "comment",
          "component": "TEXT_VIEW",
          "label": "Comment",
          "publicViewVisible": true
        },
        "3": {
          "parameterKey": "country",
          "component": "TEXT_VIEW",
          "label": "Country",
          "publicViewVisible": true
        }
      },
      "editTemplateId": "ft_apptest1552993787904_hotel_hotelcopy1",
      "replyEnabled": true,
      "editEnabled": true,
      "deleteEnabled": true,
      "voteEnabled": true,
      "socialShareEnabled": false,
      "apiCall": null,
      "embeddableScript": null,
      "deleted": true,
      "defaultViewTemplate": false
    }
  },
  {
    "_index": "local_rs_4_0_0_app_test_1552993787904",
    "_type": "conversation",
    "_id": "cnv_apptest1552993787904_tour__Anuradhapura__1552994436382",
    "_score": 1,
    "_source": {
      "modelVersion": "RS_4_0_0",
      "conversationId": "cnv_apptest1552993787904_tour__Anuradhapura__1552994436382",
      "title": "UPDATES",
      "startedBy": "usr_2012187654",
      "startedByDisplayName": "F",
      "startedAt": 1552994436382,
      "closedBy": null,
      "closedByDisplayName": null,
      "closedAt": 0,
      "lastUpdatedAt": 1552994436382,
      "status": "ONGOING",
      "conversationType": "UPDATES",
      "startedFromType": "GENERAL",
      "priorityLevel": "MEDIUM",
      "markedAsIncident": false,
      "incidentStatus": "NOT_APPLICABLE",
      "appKey": "app_test_1552993787904",
      "entityType": "tour",
      "entityId": "Anuradhapura",
      "groupKey": null,
      "limitedToShared": false,
      "sharedUserIds": [],
      "deleted": false
    }
  },
  {
    "_index": "local_rs_4_0_0_app_test_1552993787904",
    "_type": "formtemplate",
    "_id": "AWmVrobwjVbLQiy9v6fI",
    "_score": 1,
    "_source": {
      "modelVersion": "RS_4_0_0",
      "templateId": "ft_apptest1552993787904_tour_tour",
      "templateName": "tour",
      "createdUser": "usr_2012187654",
      "createdTime": 1552994436841,
      "formDescription": "",
      "thankYouNote": "Thank You",
      "formHeaderImage": "",
      "lastModifiedUser": null,
      "lastModifiedTime": null,
      "appKey": "app_test_1552993787904",
      "entityType": "tour",
      "apiCall": null,
      "entityMappedApiCall": null,
      "embeddableScript": null,
      "deleted": false,
      "defaultFormTemplate": true,
      "defaultAttachableFormTemplate": false,
      "mappedViewTemplateKey": "vt_apptest1552993787904_tour_tour",
      "components": {
        "0": {
          "cmpId": "title1552994436841",
          "component": "TEXT_FIELD",
          "parameterKey": "title",
          "required": true,
          "label": "Review Title",
          "description": null,
          "attributes": [],
          "options": [],
          "publicViewVisible": true
        },
        "1": {
          "cmpId": "overall1552994436841",
          "component": "STAR_INPUT",
          "parameterKey": "overall",
          "required": true,
          "label": "Overall Rating",
          "description": null,
          "attributes": [],
          "options": [],
          "publicViewVisible": true
        },
        "2": {
          "cmpId": "comment1552994436841",
          "component": "TEXT_AREA",
          "parameterKey": "comment",
          "required": true,
          "label": "Comment",
          "description": null,
          "attributes": [],
          "options": [],
          "publicViewVisible": true
        },
        "3": {
          "cmpId": "country1552994436841",
          "component": "COUNTRY_PICKER",
          "parameterKey": "country",
          "required": false,
          "label": "Country",
          "description": null,
          "attributes": [],
          "options": [],
          "publicViewVisible": true
        }
      },
      "embeddedEntities": [],
      "groups": []
    }
  },
  {
    "_index": "local_rs_4_0_0_app_test_1552993787904",
    "_type": "review",
    "_id": "r_anuradhapura_1552994866938",
    "_score": 1,
    "_source": {
      "modelVersion": "RS_4_0_0",
      "reviewId": "r_anuradhapura_1552994866938",
      "version": 1,
      "status": "APPROVED",
      "deleted": false,
      "readyToProcess": true,
      "appKey": "app_test_1552993787904",
      "appName": "test",
      "createdUser": "anonymous-user@app_test_1552993787904.com",
      "displayName": "Oshana",
      "createdTime": 1552994866943,
      "entityType": "tour",
      "entityId": "Anuradhapura",
      "entityName": "Anuradhapura",
      "comment": "Test Comment",
      "title": "Test",
      "parentReview": null,
      "childReviews": [],
      "numberData": [
        {
          "key": "overall",
          "value": 5
        }
      ],
      "textData": [],
      "imageData": [],
      "numberMeta": [],
      "textMeta": [
        {
          "key": "user-agent",
          "value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
        },
        {
          "key": "ip",
          "value": "0:0:0:0:0:0:0:1"
        },
        {
          "key": "source",
          "value": "DIRECT"
        },
        {
          "key": "country",
          "value": "Russia"
        }
      ],
      "replies": [],
      "sentiments": [],
      "scoredComment": [],
      "rawNumberData": {
        "overall": 5
      },
      "rawTextMeta": {
        "country": "Russia",
        "ip": "0:0:0:0:0:0:0:1",
        "source": "DIRECT",
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
      },
      "rawNumberMeta": {},
      "rawScoredComment": {},
      "pvCount": 0,
      "nvCount": 0
    }
  },
  {
    "_index": "local_rs_4_0_0_app_test_1552993787904",
    "_type": "viewtemplate",
    "_id": "AWmVq7_-jVbLQiy9v6fD",
    "_score": 1,
    "_source": {
      "modelVersion": "RS_4_0_0",
      "templateId": "vt_apptest1552993787904_hotel_hotel",
      "templateName": "hotel",
      "appKey": "app_test_1552993787904",
      "entityType": "hotel",
      "createdUser": "usr_2012187654",
      "createdTime": 1552994254811,
      "lastModifiedUser": null,
      "lastModifiedTime": null,
      "components": {
        "0": {
          "parameterKey": "title",
          "component": "TEXT_VIEW",
          "label": "Review Title",
          "publicViewVisible": true
        },
        "1": {
          "parameterKey": "overall",
          "component": "STAR_VIEW",
          "label": "Overall Rating",
          "publicViewVisible": true
        },
        "2": {
          "parameterKey": "comment",
          "component": "TEXT_VIEW",
          "label": "Comment",
          "publicViewVisible": true
        },
        "3": {
          "parameterKey": "country",
          "component": "TEXT_VIEW",
          "label": "Country",
          "publicViewVisible": true
        }
      },
      "editTemplateId": "ft_apptest1552993787904_hotel_hotel",
      "replyEnabled": true,
      "editEnabled": true,
      "deleteEnabled": true,
      "voteEnabled": true,
      "socialShareEnabled": false,
      "apiCall": null,
      "embeddableScript": null,
      "deleted": false,
      "defaultViewTemplate": true
    }
  },
  {
    "_index": "local_rs_4_0_0_app_test_1552993787904",
    "_type": "viewtemplate",
    "_id": "AWmVq8LejVbLQiy9v6fF",
    "_score": 1,
    "_source": {
      "modelVersion": "RS_4_0_0",
      "templateId": "vt_apptest1552993787904_hotel_hotelsubform",
      "templateName": "hotel Sub Form",
      "appKey": "app_test_1552993787904",
      "entityType": "hotel",
      "createdUser": "usr_2012187654",
      "createdTime": 1552994255578,
      "lastModifiedUser": null,
      "lastModifiedTime": null,
      "components": {
        "0": {
          "parameterKey": "title",
          "component": "TEXT_VIEW",
          "label": "Review Title",
          "publicViewVisible": true
        },
        "1": {
          "parameterKey": "overall",
          "component": "STAR_VIEW",
          "label": "Overall Rating",
          "publicViewVisible": true
        },
        "2": {
          "parameterKey": "comment",
          "component": "TEXT_VIEW",
          "label": "Comment",
          "publicViewVisible": true
        }
      },
      "editTemplateId": "ft_apptest1552993787904_hotel_hotelsubform",
      "replyEnabled": true,
      "editEnabled": true,
      "deleteEnabled": true,
      "voteEnabled": true,
      "socialShareEnabled": false,
      "apiCall": null,
      "embeddableScript": null,
      "deleted": false,
      "defaultViewTemplate": false
    }
  },
  {
    "_index": "local_rs_4_0_0_app_test_1552993787904",
    "_type": "viewtemplate",
    "_id": "AWmVron1jVbLQiy9v6fL",
    "_score": 1,
    "_source": {
      "modelVersion": "RS_4_0_0",
      "templateId": "vt_apptest1552993787904_tour_toursubform",
      "templateName": "tour Sub Form",
      "appKey": "app_test_1552993787904",
      "entityType": "tour",
      "createdUser": "usr_2012187654",
      "createdTime": 1552994437618,
      "lastModifiedUser": null,
      "lastModifiedTime": null,
      "components": {
        "0": {
          "parameterKey": "title",
          "component": "TEXT_VIEW",
          "label": "Review Title",
          "publicViewVisible": true
        },
        "1": {
          "parameterKey": "overall",
          "component": "STAR_VIEW",
          "label": "Overall Rating",
          "publicViewVisible": true
        },
        "2": {
          "parameterKey": "comment",
          "component": "TEXT_VIEW",
          "label": "Comment",
          "publicViewVisible": true
        }
      },
      "editTemplateId": "ft_apptest1552993787904_tour_toursubform",
      "replyEnabled": true,
      "editEnabled": true,
      "deleteEnabled": true,
      "voteEnabled": true,
      "socialShareEnabled": false,
      "apiCall": null,
      "embeddableScript": null,
      "deleted": false,
      "defaultViewTemplate": false
    }
  },
  {
    "_index": "local_rs_4_0_0_app_test_1552993787904",
    "_type": "review",
    "_id": "r_anuradhapura_1552994964151",
    "_score": 1,
    "_source": {
      "modelVersion": "RS_4_0_0",
      "reviewId": "r_anuradhapura_1552994964151",
      "version": 1,
      "status": "APPROVED",
      "deleted": false,
      "readyToProcess": true,
      "appKey": "app_test_1552993787904",
      "appName": "test",
      "createdUser": "anonymous-user@app_test_1552993787904.com",
      "displayName": "Oshana-1",
      "createdTime": 1552994964158,
      "entityType": "tour",
      "entityId": "Anuradhapura",
      "entityName": "Anuradhapura",
      "comment": "Test",
      "title": "Test-2",
      "parentReview": null,
      "childReviews": [],
      "numberData": [
        {
          "key": "overall",
          "value": 5
        }
      ],
      "textData": [],
      "imageData": [],
      "numberMeta": [],
      "textMeta": [
        {
          "key": "user-agent",
          "value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
        },
        {
          "key": "ip",
          "value": "0:0:0:0:0:0:0:1"
        },
        {
          "key": "source",
          "value": "DIRECT"
        },
        {
          "key": "country",
          "value": "Afghanistan"
        }
      ],
      "replies": [],
      "sentiments": [],
      "scoredComment": [],
      "rawNumberData": {
        "overall": 5
      },
      "rawTextMeta": {
        "country": "Afghanistan",
        "ip": "0:0:0:0:0:0:0:1",
        "source": "DIRECT",
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
      },
      "rawNumberMeta": {},
      "rawScoredComment": {},
      "pvCount": 0,
      "nvCount": 0
    }
  }
]
}

}

1 个答案:

答案 0 :(得分:0)

当您只想返回某些特定内容时,您的elasticsearch查询应包含“ _source”:“ [您想要的字段]” https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-source-filtering.html

相关问题