首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >neo4j -如何在现有数据上重新运行更新的索引?

neo4j -如何在现有数据上重新运行更新的索引?
EN

Stack Overflow用户
提问于 2013-12-31 20:08:02
回答 1查看 181关注 0票数 0

我有以下带有复合索引的BaseContent类:

代码语言:javascript
复制
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;
}

现在,我需要将索引更新为全文索引,以便支持不区分大小写的搜索。

我将其修改为:

代码语言:javascript
复制
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;
}

现在,当尝试引发服务器时,我得到了异常:

代码语言:javascript
复制
Index with the same name but different config exists!

我手动删除了之前的索引,当再次提升服务器时,它似乎正确地创建了索引。

但是,当查询现有数据时,我再次得到异常,并且我意识到它没有再次重新索引现有数据。

有没有办法对现有数据重新编制索引?

谢谢卡梅尔

EN

回答 1

Stack Overflow用户

发布于 2014-01-01 02:02:33

可以使用index类的add方法向现有索引添加节点,如下面的代码片段所示:

代码语言:javascript
复制
   @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,因为您没有在代码中显示具体的类名。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20857156

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档