【发布时间】:2015-04-16 18:03:58
【问题描述】:
我需要有关如何使用包含地图的 Spring-Data-Elasticsearch @Document 注释以最佳方式存储文档 (Java POJO) 的信息
@Document(indexName = "downloadclienterrors", type = "downloadclienterror")
public class DownloadClientErrorLogElasticsearch {
@Id
private Long id;
@Field(type = FieldType.String, index = FieldIndex.not_analyzed)
private String host;
@Field(type = FieldType.String, index = FieldIndex.not_analyzed)
private String shortMessage;
@Field(type = FieldType.String, index = FieldIndex.not_analyzed)
private String fullMessage;
@Field(type = FieldType.Date)
private String clientTimestamp;
private Integer level;
private Map<String, String> additionalFieldList;
...
}
就像在第一类中创建 POJO 一样,我可以通过我的存储库将它存储在弹性搜索实例中。
这就是我向其中添加数据的方式,我想灵活地添加哪些 JSON 字段,因为这在我的客户端软件中很灵活。
additionalFieldList.put("url", "http://www.google.de");
additionalFieldList.put("user_agent", "Browser/1.0.0 Windows");
我的问题是我还需要在附加字段列表中标记为 .not_analyzed 的字段。 (f.e additionalFieldList.url、additionalFieldList.user_agent)。 我希望在我的 Map 上也有与 String 上的 FieldIndex.not_analyzed 注释相同的行为,但当然仅适用于地图中的值。
@Field(type = FieldType.String, index = FieldIndex.not_analyzed)
private Map<String, String> additionalFieldList;
但是当我尝试存储文档时这不起作用。我收到了一个丑陋的异常。
如果有人知道一种方法,或者在 elasticsearch 中设计这样一个文档会更好,因为我在这个领域很新鲜,我很想听听一些 cmets。
感谢之前来自汉堡的灰色问候,
汤米·齐格勒
【问题讨论】:
标签: java spring elasticsearch spring-data-elasticsearch