Search using numerical values

Search indexes can also be used for non-textual values such as the integers values of cal_goal:

schema.vertexLabel('person').
  searchIndex().
  ifNotExists().
  by('person_id').
  by('badge').
  by('cal_goal').
  by('country').
  by('gender').
  by('macro_goal').
  by('name').
  create()

This example illustrates that only one search index can exist for each vertex or edge label and includes seven properties that are indexed.

With this search index, a numeric query to find all persons who have a calorie goal greater than 1200 calories is:

 g.V().has('person', 'cal_goal', gt(1200)).values('name', 'cal_goal')

results in: Five people have calorie goals of greater than 1200 calories:

==>Sharon SMITH
==>1600
==>Betsy JONES
==>1700
==>John DOE
==>1750
==>John Smith
==>1800
==>Jane DOE
==>1500

To sort the previous search, add additional methods order().by('cal_goal', incr) to sort in increasing order by calorie goals, and fold() to create a more readable result:

g.V().has('person', 'cal_goal', gt(1200)).
  order().
    by('cal_goal', incr).
  values('cal_goal', 'name').
  fold()

results in:

==>[1500, Jane DOE, 1600, Sharon SMITH, 1700, Betsy JONES, 1750, John DOE, 1800, John SMITH]

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com