Skip to content
Lorenzo Mangani edited this page Jan 14, 2018 · 4 revisions

Gun-Cassandra

Elassandra Cheat-Sheet

Index Gun-Cassandra data in ES

Always make sure keyspace is correctly configured for Elassandra indexing.

ALTER KEYSPACE gun_db WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'DC1' : 1 } AND DURABLE_WRITES = true ;

Create mapping for gun_db.gun_data with field auto-discovery and custom index on field soul:

PUT gun_db
{
  "mappings": {
    "gun_data": {
      "discover" : ".*",
      "properties": {
        "soul": {
          "type": "text"
        }
      }
    }
  }
}

Query Gun-Cassandra data from ES API

GET gun_db/_search
{
    "query" : {
        "match_all" : {}
    }
}

Using Aggregations

GET gun_db/_search
{
  "size": 0,
  "aggs": {
    "by_range": {
      "range": {
        "field": "state",
        "ranges": [
          {
            "from": 1515860865490,
            "to": 1515860865499
          }
        ]
      },
      "aggs": {
        "soul": {
          "terms": {
            "field": "soul"
          },
          "aggs": {
            "relation": {
              "terms": {
                "field": "relation"
              },
              "aggs": {
                "field": {
                  "terms": {
                    "field": "field"
                  },
                  "aggs": {
                    "value": {
                      "terms": {
                        "field": "value"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}