【问题标题】:Neo4j Cyper: Indexing numeric fieldNeo4j Cypher:索引数字字段
【发布时间】:2014-09-18 07:29:11
【问题描述】:

我正在使用 Neo4jCyper query

我的要求:

如何以优化的方式索引节点的数字字段。

我的个人节点为,

year_month  --> 2014.1 or 2014.2 or 2014.3 and so on 
desc
status

目前索引为, 在 :Person(year_month) 上创建索引

  1. 是否有任何优化的方法可以专门为数字进行索引(使用 Cyper 查询)?

我在某处发现

new ValueContext( 1999 ).indexNumeric() for indexing
  1. 以上是否可以在Cyper queries中使用?

【问题讨论】:

    标签: ruby-on-rails neo4j spring-data-neo4j


    【解决方案1】:

    属性和标签上的索引仅适用于 Cypher 中 WHERE 子句中的相等比较:http://docs.neo4j.org/chunked/stable/query-schema-index.html#schema-index-use-index-with-where

    要使用 year_month 属性上的索引,您必须指定精确匹配以优化查找。

    WITH 2014 as year, 5 as month
    WITH ((year * 12) + month) as year_month
    MATCH (p:Person { year_month: year_month })
    RETURN p
    

    以下是一些针对 year_month 上的范围查询和完全匹配查询优化 Cypher 查询的提示。

    将您的年份和月份转换为整数,而不是浮点值。

    转换为:monthIndex = (year * 12) + month

    转换自:year = (monthIndex / 12), month = (monthIndex % 12)

    使用属性monthyear 的复合索引创建节点为year_month

    WITH 2014 as year, 5 as month
    CREATE (michael:Person { 
        name: "Michael", 
        year_month: ((year * 12) + month), 
        year: year, 
        month: month })
    

    在标签Personyear_month 属性上创建索引:

     CREATE INDEX ON :Person(year_month)
    

    这种方法允许您按范围查询。

    通过5/20135/2014之间的范围查询节点:

    WITH 2013 as year_from, 5 as month_from,
         2014 as year_to, 5 as month_to
    WITH ((year_from * 12) + month_from) as date_from, 
         ((year_to * 12) + month_to) as date_to
    MATCH (p:Person)
    WHERE p.year_month >= date_from AND p.year_month <= date_to
    RETURN p
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-14
      • 1970-01-01
      • 2013-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-27
      • 1970-01-01
      相关资源
      最近更新 更多