rap-2-h
rap-2-h

Reputation: 32028

Execute raw query on elasticsearch with nodejs lib

I can perform search with NodeJS Elastcsearch lib (https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/quick-start.html).

Is there a way to execute raw queries on indices? Can I execute something like this:

PUT index
{
  "settings": {
    "analysis": {
      "normalizer": {
        "my_normalizer": {
          "type": "custom",
          "char_filter": [],
          "filter": ["lowercase", "asciifolding"]
        }
      }
    }
  },
  "mappings": {
    "_doc": {
      "properties": {
        "foo": {
          "type": "keyword",
          "normalizer": "my_normalizer"
        }
      }
    }
  }
}

... and get the result as JSON just like with Kibana. Is this possible?

Upvotes: 3

Views: 540

Answers (1)

Tarek Essam
Tarek Essam

Reputation: 4010

You can use indices.create

client.indices.create([params, [callback]])

example

client.indices.create({
   index: "persons",
   body: {
       "settings" : {
       "number_of_shards" : 1
       },
       "mappings" : {
          "type1" : {
            "properties" : {
            "field1" : { "type" : "text" }
           }
        }
     }
   }
})

check the docs indices.create

Upvotes: 2

Related Questions