Nicolas's workshop

Useful Queries

December 03, 2020

System parameters

Elasticsearch version and more basic parameters:

curl -XGET https://localhost:9200 -u admin:admin --insecure

Information on nodes:

curl -XGET https://localhost:9200/_cat/nodes?v -u admin:admin --insecure

Integrated plugins:

curl -XGET https://localhost:9200/_cat/plugins?v -u admin:admin --insecure

Information on authentication:

curl -XGET https://localhost:9200/_opendistro/_security/authinfo -u admin:admin --insecure

Information on cluster:

http://localhost:9200/_cluster/settings?include_defaults=true

Indices:

curl -XGET https://localhost:9200/_cat/indices -u admin:admin --insecure

Cloning an index from dev tools console:

POST _reindex
{
  "source": {
    "index": "portefeuille"
  },
  "dest": {
    "index": "portefeuille_test_1"
  }
}

Creating a sample index from dev tools console:

DELETE /bankdata
PUT /bankdata
POST /bankdata/1
{ "age": 42, "balance": 12000 }
POST /bankdata/2
{ "age": 28, "balance": 7000 }
POST /bankdata/3
{ "age": 51, "balance": 2300 }
POST /bankdata/4
{ "age": 15, "balance": 450 }
POST /bankdata/5
{ "age": 33 }
POST /bankdata/6
{ "age": 32 }
POST /bankdata/7
{ "age": 27 }
POST /bankdata/8
{ "age": 79 }
POST /bankdata/9
{ "age": 43, balance: null }
GET /bankdata
GET /bankdata/_search
{
    "query": {
        "match_all": {}
    }
}

Updating a given field in an index

POST lanturlu_portefeuille/_update_by_query
{
  "script": {
    "lang": "painless",
    "source": """
   try {
        String fieldName = 'nom_conseille_pv';
        String value = ctx._source[fieldName];
        ctx._source[fieldName] = value.replace(" ","_");
      }
      catch(Exception e) {
      }
    """
  }
}

Template for indexing a field as a geo_shape

PUT _template/geotemplate_geoshape_dpt
{ "index_patterns": [
  "index_pattern_title"
  ],
  "settings": {},
    "mappings": {
      "properties": {
        "wkt" :{
          "type": "geo_shape"
        }
      }
    },
    "aliases": {}
}

Painless language scripts

(((ctx?._source["MY_PARAMETER"]?:0)?:0)/((ctx?._source["OtherVariable"]?:1)?:1)?:1)

Previous: Oauth 2.0 in Spring Boot

Next: Keycloak