question

raktim.0526_188212 avatar image
raktim.0526_188212 asked raktim.0526_188212 commented

How can I make geospatial queries in Gremlin?

I have been able to create the core, search index and also able to make queries using CQL and Solr Admin. But I am having trouble making spatial parameter, facet fields, facet pivots and filterquery(fq) in Gremlin. I am aware that we can make the Geo/Solr related queries using CQL with the solr_query field. But is there a way we can make these calls using gremlin?

Currently I am making a query like this using Solr,

val test= db.searchSolrClient
.query("*:*")
.filteredQuery("vertex_type:event")
.facetPivotFields("state,region")
.rows(9999)
.getResultAsMap()
.facetPivots

Is there a way we can make something like this using Gremlin?

dsegraphsearchgeospatial
1 comment
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

raktim.0526_188212 avatar image raktim.0526_188212 commented ·

@Erick Ramirez would you happen to have any information in regard to this?

0 Likes 0 ·
bettina.swynnerton avatar image
bettina.swynnerton answered raktim.0526_188212 commented

Hi @raktim.0526_188212

I see from the comments that your follow-on questions moved to filter queries with Gremlin, away from geospatial queries.

To do the equivalent of a filter query on the solr index with gremlin, you would construct your gremlin statement like this:

g.V().hasLabel("mylabel") //this identifies the vertex table and solr core
   .has("property_name", "search_term") //this is the filter query equivalent
   .valueMap() //this gives you all the properties for the returned vertices

Using the .profile() step in the gremlin query allows you to see how the query is translated to cql and what solr query is used:

Here is an example from a test graph:

gremlin> g.V().hasLabel("product").has("product_colour", "red").valueMap().profile()
==>Traversal Metrics
Step                                                               Count  Traversers       Time (ms)    % Dur
=============================================================================================================
__.V().hasLabel("product").has("product_colour"...                   315         315          40.207    93.91
  CQL statements ordered by overall duration                                                  34.226
    \_1=SELECT * FROM products2.product WHERE solr_query = '{"q":"*:*", "fq":["product_colour:red"]}' LIMIT 2
        147483647 / Duration: 34 ms / Count: 1
HasStep([~label.eq(product), product_colour.eq(...                   315         315           0.688     1.61
PropertyMapStep(value)                                               315         315           0.911     2.13
ReferenceElementStep                                                 315         315           1.008     2.35
                                            >TOTAL                     -           -          42.815        -


For documentation on using a search index in Gremlin queries, see here:

https://docs.datastax.com/en/dse/6.8/dse-dev/datastax_enterprise/graph/using/useIndexes.html


To do a groupCount (like a facet count) on the property, you can do the following. Note that this does not use the search index:

gremlin> g.V().hasLabel("product").groupCount().by("product_colour")
==>{magenta=309, pink=311, yellow=332, turquoise=351, cyan=334, gold=324, red=315, fuchsia=313, white=305, olive=322, ivory=318, lavender=318, azure=340, plum=291, tan=301, green=352, mint green=303, lime=338, salmon=306, black=333, violet=324, teal=334, grey=304, orange=346, blue=334, sky blue=329, purple=334, silver=320, indigo=328, maroon=302, orchid=329}


gremlin> g.V().hasLabel("product").groupCount().by("product_colour").profile()
==>Traversal Metrics
Step                                                               Count  Traversers       Time (ms)    % Dur
=============================================================================================================
__.V().hasLabel("product")                                         10000       10000         116.203    89.79
  CQL statements ordered by overall duration                                                   5.257
    \_1=SELECT * FROM products2.product / Duration: 5 ms / Count: 1 / Index type: Table: product
HasStep([~label.eq(product)])                                      10000       10000           4.746     3.67
GroupCountStep(value(product_colour))                                  1           1           8.370     6.47
ReferenceElementStep                                                   1           1           0.100     0.08
                                            >TOTAL                     -           -         129.420        -


1 comment Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

raktim.0526_188212 avatar image raktim.0526_188212 commented ·

@bettina.swynnerton thank you for your reply.

0 Likes 0 ·
Erick Ramirez avatar image
Erick Ramirez answered raktim.0526_188212 commented

@raktim.0526_188212 It looks like you're doing something in Scala but it doesn't appear to be a geospatial query.

A typical spatial query answers questions like these:

  • Where is the nearest train station?
  • Which groceries are within a 5-mile radius?

You can do geospatial traversals with DSE Graph. There are examples in this document on how to do it. However, I'm not sure if it's relevant to your question because it doesn't seem like you're trying to do the same thing. Cheers!

2 comments Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

raktim.0526_188212 avatar image raktim.0526_188212 commented ·

@Erick Ramirez i have been able to do these geospatial queries. I guess my question should have been, how can I make facet fields, facet pivots and filterquery(fq) in Gremlin. I could not find any documentation on the datastax website.

In CQL i can use something like this to make it work.

solr_query='{"q":"*:*","fq":"geo:\"Intersects(-117.044313 47.762451)\""}'

But I wanted to know if there is a way to make queries with facet fields, facet pivots and filterquery(fq) in Gremlin?

0 Likes 0 ·
raktim.0526_188212 avatar image raktim.0526_188212 commented ·

@Erick Ramirez Would really appreciate if you could help me out with the above comment?

0 Likes 0 ·