【问题标题】:Neo4j: Change legacy index from exact to fulltextNeo4j:将旧索引从精确更改为全文
【发布时间】:2014-08-28 13:31:40
【问题描述】:

在我的 Neo4j(2.1.1 社区版)数据库中,我有一个名为 node_auto_index 的 Lucene 旧索引:

GET http://localhost:7474/db/data/index/node/

{
    "node_auto_index": {
        "template": "http://localhost:7474/db/data/index/node/node_auto_index/{key}/{value}",
        "provider": "lucene",
        "type": "exact"
    }
}

现在我想将类型从“精确”更改为“全文”。我怎样才能使用 REST 做到这一点?我尝试了以下方法,但都没有奏效:

删除并重新创建

我尝试在重新创建为“全文”之前先删除它,但它是只读的:

DELETE http://localhost:7474/db/data/index/node/node_auto_index/node_auto_index

{
    "message": "read only index",
    "exception": "UnsupportedOperationException",
    "fullname": "java.lang.UnsupportedOperationException",
    "stacktrace": [
        "org.neo4j.kernel.impl.coreapi.AbstractAutoIndexerImpl$ReadOnlyIndexToIndexAdapter.readOnlyIndex(AbstractAutoIndexerImpl.java:254)",
        "org.neo4j.kernel.impl.coreapi.AbstractAutoIndexerImpl$ReadOnlyIndexToIndexAdapter.delete(AbstractAutoIndexerImpl.java:290)",
        "org.neo4j.server.rest.web.DatabaseActions.removeNodeIndex(DatabaseActions.java:437)",
        "org.neo4j.server.rest.web.RestfulGraphDatabase.deleteNodeIndex(RestfulGraphDatabase.java:935)",
        "java.lang.reflect.Method.invoke(Unknown Source)",
        "org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139)",
        "java.lang.Thread.run(Unknown Source)"
    ]
}

POST 替换

POST http://localhost:7474/db/data/index/node/
{
  "name" : "node_auto_index",
  "config" : {
    "to_lower_case" : "true",
    "type" : "fulltext",
    "provider" : "lucene"
  }
}

 

{
    "message": "Supplied index configuration:\n{to_lower_case=true, type=fulltext, provider=lucene}\ndoesn't match stored config in a valid way:\n{provider=lucene, type=exact}\nfor 'node_auto_index'",
    "exception": "IllegalArgumentException",
    "fullname": "java.lang.IllegalArgumentException",
    "stacktrace": [
        "org.neo4j.kernel.impl.coreapi.IndexManagerImpl.assertConfigMatches(IndexManagerImpl.java:168)",
        "org.neo4j.kernel.impl.coreapi.IndexManagerImpl.findIndexConfig(IndexManagerImpl.java:149)",
        "org.neo4j.kernel.impl.coreapi.IndexManagerImpl.getOrCreateIndexConfig(IndexManagerImpl.java:209)",
        "org.neo4j.kernel.impl.coreapi.IndexManagerImpl.getOrCreateNodeIndex(IndexManagerImpl.java:314)",
        "org.neo4j.kernel.impl.coreapi.IndexManagerImpl.forNodes(IndexManagerImpl.java:302)",
        "org.neo4j.server.rest.web.DatabaseActions.createNodeIndex(DatabaseActions.java:398)",
        "org.neo4j.server.rest.web.RestfulGraphDatabase.jsonCreateNodeIndex(RestfulGraphDatabase.java:830)",
        "java.lang.reflect.Method.invoke(Unknown Source)",
        "org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139)",
        "java.lang.Thread.run(Unknown Source)"
    ]
}

【问题讨论】:

    标签: rest lucene neo4j


    【解决方案1】:

    此问题的所有未来读者。

    我遇到了类似的情况,并找到了一种更简洁的方法来解决这个问题。请尝试以下步骤,而不是删除 node_auto_index。

    打开 db 的 shell / 命令行:

    - neo4j-sh (0)$ index --get-config node_auto_index
    - ==> {
    - ==> "provider": "lucene",
    - ==> "type": "exact"
    - ==> }
    - neo4j-sh (0)$ index --set-config node_auto_index type fulltext
    - ==> INDEX CONFIGURATION CHANGED, INDEX DATA MAY BE INVALID
    - neo4j-sh (0)$ index --get-config node_auto_index
    - ==> {
    - ==> "provider": "lucene",
    - ==> "type": "fulltext"
    - ==> }
    - neo4j-sh (0)$
    

    对我来说工作得很好。希望这可以帮助有需要的人:-)

    【讨论】:

    • 效果很好!完成此操作后,您需要触发重新索引。一种简单的方法是执行如下更新查询:MATCH (n) WHERE has(c.<some-indexed-property>) SET c.<some-indexed-property> = c.<some-indexed-property>
    • 如果这里有人愿意就为什么这个操作对我停止工作提供建议,我将非常感激。 My post.
    【解决方案2】:

    Neo4j 不允许删除自动索引 node_auto_indexrelationship_auto_index,也不允许通过 REST 或任何其他 API。

    但是有一个肮脏的技巧来完成这项工作。这个技巧将删除所有自动和其他遗留索引。它不涉及架构索引。 请注意,这是一项潜在的危险操作,因此请确保您有一个有效的备份。停止数据库,然后做一个

    rm -rf data/graph.db/index*
    

    重新启动数据库,所有自动索引和旧索引都消失了。

    【讨论】:

    • 它起作用了,在 Windows 上我删除了 myinstallpath\mydbname\index 文件夹和 myinstallpath\mydbname\index.db 文件(仅删除上述一个是不够的)并且自动索引消失了,所以我可以创建一个新的全文自动索引。
    猜你喜欢
    • 2014-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 2018-12-07
    • 1970-01-01
    • 2012-03-23
    相关资源
    最近更新 更多