我有以下带有复合索引的BaseContent类:
public abstract class BaseContent<D extends BaseContentDTO> extends BaseEntity {
/* The FULLTEXT index allows to search on non case-sensitive queries */
@Indexed(indexName = "search_content")
@NotNull
protected String name;
@Indexed(indexName = "search_content")
protected Integer year;
}
现在,我需要将索引更新为FULLTEXT索引,以支持非区分大小写的搜索。
我这样修改了它:
public abstract class BaseContent<D extends BaseContentDTO> extends BaseEntity {
/* The FULLTEXT index allows to search on non case-sensitive queries */
@Indexed(indexName = "search_content", indexType=IndexType.FULLTEXT)
@NotNull
protected String name;
@Indexed(indexName = "search_content", indexType=IndexType.FULLTEXT)
protected Integer year;
}
现在,当尝试引发服务器时,我得到了异常:
Index with the same name but different config exists!
我手动删除了上一个索引,再次提升服务器时,它似乎正确地创建了索引。
但是,在查询现有数据时,我再次得到了异常,并且我意识到它没有再次重新索引现有数据。
有没有办法对现有数据进行重新索引?
由于 卡梅尔
答案 0 :(得分:1)
您可以使用 Index 类的 add 方法将节点添加到现有索引中,如下面的代码片段所示:
@Autowired Neo4jOperations neo4jOperations;
Index index = neo4jOperations.getGraphDatabase().getIndex("search_content");
Collection<YourClass> objects = neo4jOperations.findAll(YourClass.class).as(Collection.class);
for (YourClass object: objects) {
Node node = neo4jOperations.getNode(object.getId());
index.add(node, "name", node.getProperty("name"));
index.add(node, "year", node.getProperty("year"));
}
我使用了占位符类名 YourClass ,因为您没有在代码中显示具体的类名。