Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 418
rap-2-h Avatar asked Feb 16 '26 04:02

rap-2-h


1 Answers

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

like image 143
Tarek Essam Avatar answered Feb 17 '26 21:02

Tarek Essam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!