【发布时间】:2021-12-22 02:06:52
【问题描述】:
当前我正在开发一个 Spring Boot 项目,以使用 Spring Data ElasticSearch(版本 4.1.7)从特定的 Elastic 搜索索引中获取数据。我能够连接到弹性搜索并获取与特定索引关联的所有数据。但是索引中有一些字段返回空值。弹性搜索中的索引中存在实际值。
由于字段类型不正确,我在检索特定字段时遇到问题。我创建了一个文档类
@Document(indexName = "netstat*")
@Setting(settingPath = "static/es-settings.json")
public class NetworkStats {
@Id
@Field(type = FieldType.Keyword)
private String id;
@Field
private String timeStamp ;
@Field(type = FieldType.Text)
private String podName ;
@Field(type = FieldType.Text)
private String iporHost ;
@Field(type = FieldType.Auto)
private String connectionCount ;
@Field(type = FieldType.Text)
private String command ;
}
除了上述之外,我还定义了该字段的 getter 和 setter。我无法检索字段 connectionCount、iporHost、podName、timeStamp 的值。尽管这些字段在弹性索引中具有值。
下面来自 ElasticSearch 的示例数据
{
"_index": "netstat-2021.11.09",
"_type": "_doc",
"_id": "0sJmA30BW7LXXVrK0nCg",
"_score": 1.0,
"_source": {
"podname": "logindeployment-5479f7-4f2qr",
"input": {
"type": "log"
},
"iporhost": "6200",
"tags": [],
"command": "OUTESTAB",
"agent": {
"version": "7.15.1",
"id": "e8feeb4e-1f9e-41b2-bcba-38e507d176db",
"type": "filebeat",
"hostname": "BL1726L",
"name": "BL1726L",
"ephemeral_id": "c2859ece-3e95-4204-909d-af59322b9fa2"
},
"timestamp": "05-10-21T13:17:25.014719626",
"ecs": {
"version": "1.11.0"
},
"connectionscount": "2",
"@timestamp": "2021-11-09T06:31:29.104Z",
"log": {
"offset": 1002,
"file": {
"path": "D:\\elastic_stack\\data\\log\\netStats.log"
}
}
}
},
需要有关如何检索上述字段的数据的帮助。我猜字段映射存在一些问题。非常感谢您对此提供任何帮助。
【问题讨论】:
标签: java spring elasticsearch spring-data-elasticsearch