aboutsummaryrefslogtreecommitdiff

Elasticsearch

Introduction

GeneNetwork uses elasticsearch (ES) for all things considered 'state'. One example is user collections, another is user management.

Example

To get the right environment, first you can get a python REPL with something like

env GN2_PROFILE=~/opt/gn-latest ./bin/genenetwork2 ../etc/default_settings.py -cli python

(make sure to use the correct GN2PROFILE!)

Next try

from elasticsearch import Elasticsearch, TransportError

es = Elasticsearch([{ "host": 'localhost', "port": '9200' }])

# Dump all data

es.search("*")

# To fetch an E-mail record from the users index

record = es.search(
            index = 'users', doc_type = 'local', body = {
                "query": { "match": { "email_address": "myname@email.com" } }
            })

# It is also possible to do wild card matching

q = { "query": { "wildcard" : { "full_name" : "pjot*" } }}
es.search(index = 'users', doc_type = 'local', body = q)

# To get elements from that record:

record['hits']['hits'][0][u'_source']['full_name']
u'Pjotr'

record['hits']['hits'][0][u'_source']['email_address']
u"myname@email.com"

Health

ES provides support for checking its health:

curl -XGET http://localhost:9200/_cluster/health?pretty=true

{
  "cluster_name" : "asgard",
  "status" : "yellow",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 5,
  "active_shards" : 5,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 5
}

Yellow means just one instance is running (no worries).

To get full cluster info

curl -XGET "localhost:9200/_cluster/stats?human&pretty"

#+BEGINSRC json { "nodes" : { "total" : 1, "successful" : 1, "failed" : 0 }, "clustername" : "elasticsearch", "timestamp" : 1529050366452, "status" : "yellow", "indices" : { "count" : 3, "shards" : { "total" : 15, "primaries" : 15, "replication" : 0.0, "index" : { "shards" : { "min" : 5, "max" : 5, "avg" : 5.0 }, "primaries" : { "min" : 5, "max" : 5, "avg" : 5.0 }, "replication" : { "min" : 0.0, "max" : 0.0, "avg" : 0.0 } } }, "docs" : { "count" : 14579, "deleted" : 0 }, "store" : { "size" : "44.7mb", "sizeinbytes" : 46892794 }, "fielddata" : { "memorysize" : "0b", "memorysizeinbytes" : 0, "evictions" : 0 }, "querycache" : { "memorysize" : "0b", "memorysizeinbytes" : 0, "totalcount" : 0, "hitcount" : 0, "misscount" : 0, "cachesize" : 0, "cachecount" : 0, "evictions" : 0 }, "completion" : { "size" : "0b", "sizeinbytes" : 0 }, "segments" : { "count" : 24, "memory" : "157.3kb", "memoryinbytes" : 161112, "termsmemory" : "122.6kb", "termsmemoryinbytes" : 125569, "storedfieldsmemory" : "15.3kb", "storedfieldsmemoryinbytes" : 15728, "termvectorsmemory" : "0b", "termvectorsmemoryinbytes" : 0, "normsmemory" : "10.8kb", "normsmemoryinbytes" : 11136, "pointsmemory" : "111b", "pointsmemoryinbytes" : 111, "docvaluesmemory" : "8.3kb", "docvaluesmemoryinbytes" : 8568, "indexwritermemory" : "0b", "indexwritermemoryinbytes" : 0, "versionmapmemory" : "0b", "versionmapmemoryinbytes" : 0, "fixedbitset" : "0b", "fixedbitsetmemoryinbytes" : 0, "maxunsafeautoidtimestamp" : -1, "filesizes" : { } } }, "nodes" : { "count" : { "total" : 1, "data" : 1, "coordinatingonly" : 0, "master" : 1, "ingest" : 1 }, "versions" : [ "6.2.1" ], "os" : { "availableprocessors" : 16, "allocatedprocessors" : 16, "names" : [ { "name" : "Linux", "count" : 1 } ], "mem" : { "total" : "125.9gb", "totalinbytes" : 135189286912, "free" : "48.3gb", "freeinbytes" : 51922628608, "used" : "77.5gb", "usedinbytes" : 83266658304, "freepercent" : 38, "usedpercent" : 62 } }, "process" : { "cpu" : { "percent" : 0 }, "openfiledescriptors" : { "min" : 415, "max" : 415, "avg" : 415 } }, "jvm" : { "maxuptime" : "1.9d", "maxuptimeinmillis" : 165800616, "versions" : [ { "version" : "9.0.4", "vmname" : "OpenJDK 64-Bit Server VM", "vmversion" : "9.0.4+11", "vmvendor" : "Oracle Corporation", "count" : 1 } ], "mem" : { "heapused" : "1.1gb", "heapusedinbytes" : 1214872032, "heapmax" : "23.8gb", "heapmaxinbytes" : 25656426496 }, "threads" : 110 }, "fs" : { "total" : "786.4gb", "totalinbytes" : 844400918528, "free" : "246.5gb", "freeinbytes" : 264688160768, "available" : "206.5gb", "availableinbytes" : 221771468800 }, "plugins" : [ ], "networktypes" : { "transporttypes" : { "netty4" : 1 }, "httptypes" : { "netty4" : 1 } } } } #+BEGINSRC json