使用 Java 字段映射弹性索引字段的问题

Issues with Mapping Elastic Index fields with Java Fields

目前我正在开发一个 spring 引导项目,使用 Spring Data ElasticSearch(版本 4.1.7)从特定的 Elastic 搜索索引中获取数据。我能够连接到弹性搜索并获取与特定索引关联的所有数据。但是索引中有一些字段返回空值。实际值存在于弹性搜索的索引中。
由于字段类型不正确,我在检索特定字段时遇到问题。我创建了一个文档 Class 其中

@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 defined.Im unabel 以检索字段 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"
                    }
                }
            }
        },

需要有关如何检索上述数据的帮助fields.I猜测字段映射存在一些问题。非常感谢对此的任何帮助。

Elasticsearch 中的字段名称似乎都是小写的。您的财产有骆驼案。所以需要定义名称:

@Field(type = FieldType.Text, name ="podname")
private String podName ; 

如果您没有定义 FieldType 或使用 FieldType.Auto,则不会写入任何映射,Elasticsearch 将尝试猜测类型。您应该定义正确的类型以确保转换按要求完成。

特别是对于 timestamp 字段,您应该定义与索引中的内容相匹配的日期格式。

由于索引存在,您应该确保在实体定义中使用与索引中已使用的类型相同的类型。