将长文本添加到索引时Neo4j - 500内部服务器错误

时间:2013-03-05 10:12:44

标签: neo4j py2neo

我正在使用Neo4j-community-1.9.M04,与python rest客户端连接(py2neo 1.4.5)。 当我尝试向索引添加长文本时,服务器返回500内部服务器错误。

使用py2neo客户端,我喜欢:

everything_idx = gdb.get_or_create_index(neo4j.Node, "everything", config={"type": "fulltext"})
everything_idx.add("everything", long_text, recommendation_node)

其中long_text是一个包含从URL解析的文本的变量,而adv_node是我要索引的Node实例。

这就是我在py2neo日志中的内容:

INFO 2013-03-05 11:47:17,855 rest 11104 1108 POST /db/data/index/node/everything {'Content-Type': 'application/json', 'X-Stream': 'true', 'Accept': 'application/json', 'User-Agent': 'py2neo/1.4.6 (win32; python/2.7.2)'} (47486 bytes)
INFO 2013-03-05 11:47:17,894 rest 11104 1108 500 Internal Server Error {'content-length': '0', 'server': 'Jetty(6.1.25)'}

在Neo4j日志中,我有以下内容: 的console.log:

11:47:19.733 [1695422617@qtp-1319007734-22] WARN  org.mortbay.log - header full: java.lang.ArrayIndexOutOfBoundsException
11:47:19.734 [1695422617@qtp-1319007734-22] ERROR org.mortbay.log - /db/data/index/node/everything
javax.ws.rs.WebApplicationException: null
        at org.neo4j.server.rest.repr.OutputFormat$1.write(OutputFormat.java:156) ~[neo4j-server-1.9.M04.jar:1.9.M04]
        at com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:71) ~[jersey-core-1.9.jar:1.9]
        at com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:57) ~[jersey-core-1.9.jar:1.9]
        at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306) ~[jersey-server-1.9.jar:1.9]
        at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437) ~[jersey-server-1.9.jar:1.9]
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349) ~[jersey-server-1.9.jar:1.9]
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339) ~[jersey-server-1.9.jar:1.9]
        at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) ~[jersey-server-1.9.jar:1.9]
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) ~[jersey-server-1.9.jar:1.9]
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699) ~[jersey-server-1.9.jar:1.9]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) ~[servlet-api-2.5-20081211.jar:na]
        at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) ~[jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390) ~[jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.Server.handle(Server.java:326) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:943) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410) [jetty-6.1.25.jar:6.1.25]
        at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582) [jetty-util-6.1.25.jar:6.1.25]

并在neo4j.0.0.log中:

Mar 5, 2013 11:47:19 AM com.sun.jersey.server.impl.application.WebApplicationImpl _handleRequest
SEVERE: The response of the WebApplicationException cannot be utilized as the response is already committed. Re-throwing to the HTTP container
javax.ws.rs.WebApplicationException
        at org.neo4j.server.rest.repr.OutputFormat$1.write(OutputFormat.java:156)
        at com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:71)
        at com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:57)
        at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306)
        at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
        at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
        at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
        at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
        at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
        at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
        at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
        at org.mortbay.jetty.Server.handle(Server.java:326)
        at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
        at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:943)
        at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
        at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
        at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
        at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
        at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

我认为问题可能是我正在使用的其他客户端,所以我更改了它(我先尝试过neo4jrestclient)。

任何想法?

1 个答案:

答案 0 :(得分:1)

事实证明,将此节点添加到全文索引失败的原因是它不在事务中执行。 我尝试使用以下代码,使用neo4jrestclient进行事务并且它可以工作:

import urllib2, logging, logging.config, pdb, traceback
from neo4jrestclient.client import GraphDatabase, Node, Relationship

gdb = GraphDatabase("http://localhost:7474/db/data/")

everything_idx = gdb.nodes.indexes.create("everything_", type="fulltext", provider="lucene")
node = gdb.node(name="Node1")

with gdb.transaction() as tx:
    try:
        request = urllib2.urlopen("http://www.tripadvisor.com/Restaurant_Review-g35805-d451303-Reviews-Ramova_Grill-Chicago_Illinois.html")

        if request.getcode() == 200:
            long_text = unicode(request.read(), "utf-8")
            everything_idx["everything"][long_text] = node
    except Exception as e:
        pdb.set_trace()