查询索引时出现500内部服务器错误

时间:2013-09-27 05:12:16

标签: neo4jclient

我正在尝试使用Neo4j和Neo4jClient;我试图尝试的第一件事是插入一系列带有publication_number属性的节点。在插入每个节点之前,我想检查以确保不存在具有相同发布号的另一个节点。为此我创建了一个publication_number的索引,然后我查询。

这是我到目前为止的代码。 (显然上面的所有逻辑都没有实现,但我甚至无法实现这一点。)

class Program
{
    static void Main(string[] args)
    {
        var client = new GraphClient(new Uri("http://192.168.12.31:7474/db/data"));
        client.Connect();

        // create index
        client.CreateIndex("publication_number_idx", new IndexConfiguration
        {
            Provider = IndexProvider.lucene,
            Type = IndexType.exact
        },
        IndexFor.Node);

        // create record
        Record record1 = new Record { publication_number = "1" };
        Record record2 = new Record { publication_number = "2" };

        // add record1 to graph and index
        var record1Ref = client.Create(record1);
        client.ReIndex(record1Ref, new[] { new IndexEntry ("publication_number_idx") { { "publication_number", record1.publication_number } } });
        Console.WriteLine("Added record1 at {0}", record1Ref.Id);

        // add record2 to graph and index
        var record2Ref = client.Create( record2, 
                                        new[] { new Cites(record1Ref) { Direction = RelationshipDirection.Outgoing } },
                                        new[] { new IndexEntry("publication_number_idx") { {"publication_number", record2.publication_number } } });
        Console.WriteLine("Added record2 at {0}", record2Ref.Id);

        // 500 error here
        client.QueryIndex<Record>("publication_number_idx", IndexFor.Node, @"START n=node:publication_number_idx(publication_number = ""2"") RETURN n;");

    }

}

public class Cites : Relationship, IRelationshipAllowingSourceNode<Record>, IRelationshipAllowingTargetNode<Record>
{
    public Cites(NodeReference targetNode)
        : base(targetNode)
    {
    }

    public const string TypeKey = "CITES";

    public override string RelationshipTypeKey
    {
        get { return TypeKey; }
    }
}

我似乎成功添加了备注并更新了​​索引。我可以在控制台中使用Cypher查询索引;但是,当我使用与Neo4J客户端相同的Cypher查询时,我在查询中得到500内部服务器错误。

未处理的异常:System.ApplicationException:执行请求时收到意外的HTTP状态。

  

响应状态为:500内部服务器错误

     

Neo4j的回复(可能包括有用的细节!)是:{
  “exception”:“NullPointerException”,“fullname”:   “java.lang.NullPointerException”,“stacktrace”:[   “org.apache.lucene.util.SimpleStringInterner.intern(SimpleStringInterner.java:54)”,   “org.apache.lucen e.util.StringHelper.intern(StringHelper.java:39)”,   “org.apache.lucene.index.Term。(Term.java:38)”,“org.apache.luce   ne.queryParser.QueryParser.getFieldQuery(QueryParser.java:643)”,   “org.apache.lucene.queryParser.QueryParser.Term(QueryPa   rser.java:1436)”,   “org.apache.lucene.queryParser.QueryParser.Clause(QueryParser.java:1319)”,   “org.apache.lucene.queryPar   ser.QueryParser.Query(QueryParser.java:1245)”,   “org.apache.lucene.queryParser.QueryParser.TopLevelQuery(QueryParser.java   :1234)”,   “org.apache.lucene.queryParser.QueryParser.parse(QueryParser.java:206)”,   “org.neo4j.index.impl.lucene.IndexType .query(IndexType.java:300)”,   “org.neo4j.index.impl.lucene.LuceneIndex.query(LuceneIndex.java:227)”,   “org.neo4j.server.re   st.web.DatabaseActions.getIndexedNodesByQuery(DatabaseActions.java:889)”,   “org.neo4j.server.rest.web.DatabaseActions.get   IndexedNodesByQuery(DatabaseActions.java:872)”,   “org.neo4j.server.rest.web.RestfulGraphDatabase.getIndexedNodesByQuery(R   estfulGraphDatabase.java:707)”,   “java.lang.reflect.Method.invoke(Method.java:606)”,   “org.neo4j.server.rest.security.Secu   rityFilter.doFilter(SecurityFilter.java:112)“]} at   Neo4jClient.GraphClient.SendHttpRequest(HttpRequestMessage请求,   String commandDescription,HttpStatusCode [] ex pectedStatusCodes)in   C:\ TeamCity的\ buildAgent \工作\ f1c4cf3efbf1b05e \ Neo4jClient \ GraphClient.cs:行   137在Neo4jClient.GraphClient.QueryIndex [TNode](String indexName,   C:\ TeamCity \ buildA中的IndexFor indexFor,String query)   gent \ work \ f1c4cf3efbf1b05e \ Neo4jClient \ GraphClient.cs:第1168行   Antares.Program.Main(String [] args)在c:\ Users \ Yellick中   Chris \ Documents \ Visual Studio 2012 \ Projects \ Antares \ Antare   s \ Program.cs:第41行

1 个答案:

答案 0 :(得分:1)

我不确定500错误是什么,但让查询工作的解决方案是删除'QueryIndex'调用(已过时)并将其替换为Cypher表示法,因此:

var query = client.Cypher
        .Start(new {n = Node.ByIndexLookup("publication_number_idx", "publication_number", "2")})
        .Return<Record>("n");

var results = query.Results;

'QueryIndex'中使用的查询与您的格式不同,如果您查看Neo4jclient Index Documentation,您需要将=替换为:并将其换行'喜欢这样:

client.QueryIndex<Record>("publication_number_idx", IndexFor.Node, @"START n=node:publication_number_idx('publication_number: ""2""') RETURN n;");

这并不能解决500错误。