【发布时间】:2018-06-09 16:23:50
【问题描述】:
根据我下面的实现,我无法从 ES 中检索父/子文档。
第 1 步:关系
{
"versionjoin": {
"properties": {
"my_join_field": {
"type": "join",
"relations": {
"version": "accountversion"
}
}
}
}
}
第 2 步:这就是我索引父文档的方式。
{
String pattern = YYYY_MM_DD_HH_MM_SS;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
String date = simpleDateFormat.format(index_timestamp);
JSONObject obj = new JSONObject();
JSONObject joinObject = new JSONObject();
obj.put(VERSIONNUMBER, versionNumber);
obj.put(VERSIONDATE, date);
obj.put("my_join_field","version");
client.prepareIndex(
versionIndexName,
versionJoinType)
.setId(versionNumber)
.setSource(obj.toString(),XContentType.JSON)
.execute()
.actionGet();
}
第 3 步:这就是我尝试索引子文档的方式。
JsonNode node = serializeMapper.readTree(json);
ObjectNode addedNode = ((ObjectNode) node).putObject("my_join_field");
addedNode
.put("name", "accountversion")
.put("parent", association.getVersion());
String modifiedJson = serializeMapper.writeValueAsString(addedNode);
indexResponse = client.prepareIndex(versionIndexName, versionJoinType)
.setId(String.valueOf(association.getId() + ":" +
association.getVersion()))
.setRouting(association.getVersion())
.setSource(modifiedJson,XContentType.JSON).get();
当我尝试使用文档 ID 和路由检索文档时,我在结果中看不到任何文档。我最近将 ES 从 2.4 迁移到 6.2,并将上述实现更改为从同一索引读取父文档和子文档。由于类型支持在 ES 6.2 中已被弃用。任何人都可以建议我是否以不正确的方式做任何事情。
【问题讨论】:
标签: elasticsearch elasticsearch-5