Я мигрирую с эластичного 2 на эластичный 6, где у меня было 2 документа с родительскими дочерними отношениями (1 индекс с 2 различными типами). В то время как кодирование в версии эластичного 6 кажется, что индекс и тип должны быть одинаковыми. Как можно я перенести код для работы в эластичном
добавление примера кода для версии 2.0 (рабочая).
нужно сделать то же самое отображение для эластика 6.
файл родительского сопоставления
{
"graph": {
"properties": {
"graph": {
"properties": {
"id": {
"type": "string",
"index": "not_analyzed"
},
"typeId": {
"type": "string",
"index": "not_analyzed"
}
}
},
"graphId": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
дочерний файл сопоставления
{
"adjacency": {
"_parent": {
"type": "graph"
},
"_routing": {
"required": true
},
"properties": {
"Id": {
"type": "string",
"index": "not_analyzed"
},
"parentId": {
"type": "string",
"index": "not_analyzed"
},
"adjacency": {
"properties": {
"dst": {
"properties": {
"dstId": {
"type": "string",
"index": "not_analyzed"
}
}
},
"src": {
"properties": {
"srcId": {
"type": "string",
"index": "not_analyzed"
}
}
},
"mode": {
"type": "string"
},
"type": {
"type": "string",
"index": "not_analyzed"
},
"versionId": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
родительская модель
@Document(createIndex = false, indexName = "graph", type = "graph")
@Mapping(mappingPath = "mapping_type_graph.json") -->Mentioned above
public class graphDoc {
@Id
private String graphId = null;
@Field(type = FieldType.Object)
private graph graph = null;
public String getgraphId() {
return graphId;
}
public void setgraphId(String graphId) {
this.graphId = graphId;
}
public graph getgraph() {
return graph;
}
public void setgraph(graph graph) {
this.graph = graph;
}
public graph graph(graph graph) {
this.graph = graph;
return this.graph;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((graphId == null) ? 0 : graphId.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
graphDoc other = (graphDoc) obj;
if (graphId == null) {
if (other.graphId != null)
return false;
} else if (!graphId.equals(other.graphId)) {
return false;
}
return true;
}
@Override
public String toString() {
return "graphDoc [graphId=" + graphId + "]";
}
}
детская модель
@Document(createIndex = false, indexName = "graph", type = "adjacency")
@Mapping(mappingPath = "mapping_type_adjacency.json") --> mentioned above
public class adjacencyDoc {
@Id
private String Id = null;
@Field(type = FieldType.String)
@Parent(type = "graph")
private String parentId = null;
@Field(type = FieldType.Object)
private adjacency adjacency = null;
public String getId() {
return Id;
}
public void setId(String Id) {
this.Id = Id;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public adjacency getadjacency() {
return adjacency;
}
public void setadjacency(adjacency adjacency) {
this.adjacency = adjacency;
}
public adjacency adjacency(adjacency adjacency) {
this.adjacency = adjacency;
return this.adjacency;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((adjacency == null) ? 0 : adjacency.hashCode());
result = prime * result + ((Id == null) ? 0 : Id.hashCode());
result = prime * result + ((parentId == null) ? 0 : parentId.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
adjacencyDoc other = (adjacencyDoc) obj;
if (adjacency == null) {
if (other.adjacency != null)
return false;
} else if (!adjacency.equals(other.adjacency)) {
return false;
}
if (Id == null) {
if (other.Id != null)
return false;
} else if (!Id.equals(other.Id)) {
return false;
}
if (parentId == null) {
if (other.parentId != null)
return false;
} else if (!parentId.equals(other.parentId)) {
return false;
}
return true;
}
@Override
public String toString() {
return "adjacencyDoc [Id=" + Id + ", parentId=" + parentId
+ ", adjacency=" + adjacency + "]";
}
}
@SpringBootApplication
public class Launcher { //NOSONAR
public static void main(String[] args) {
SpringApplication.run(Launcher.class, args); //NOSONAR
}
@Autowired
private ElasticsearchTemplate elasticsearchTemplate;
@EventListener
public void onApplicationReady(ApplicationReadyEvent e) {
//lazily create child index and mapping before creating parent index and mapping
elasticsearchTemplate.createIndex(AdjacencyDoc.class);
elasticsearchTemplate.putMapping(AdjacencyDoc.class);
elasticsearchTemplate.createIndex(GraphDoc.class);
elasticsearchTemplate.putMapping(GraphDoc.class);
}
}