Elasticsearch-js: When creating an index, `settings`, `mappings`, and `aliases` are ignored

Created on 29 Nov 2015  路  1Comment  路  Source: elastic/elasticsearch-js

Some settings you need to define when the index is created and can never change (like number of shards). The node library has no support for many of the options the REST API supports when creating indexes.

I would expect params to also accept mappings, settings, warmers, and aliases. The following would be a valid params argument to client.indices.create(payload, callback)

var payload = {
  "index": "events-2015-11",

  "settings": {
    "number_of_shards": 100,
    "number_of_replicas": 1
  },

  "mappings": {
    "event": { 
      "properties": { 
        "ip":       { "type": "string"  }, 
        "guid":     { "type": "string"  }, 
        "userId":   { "type": "string"  }, 
        "key":      { "type": "string"  }, 
        "value":    { "type": "string"  }, 
        "type":     { "type": "string"  }, 

        "campaign": { "type": "string"  }, 
        "source":   { "type": "string"  }, 
        "medium":   { "type": "string"  }, 
        "quantity": { "type": "double"  },

        "data":     { "type": "object"  },

        "createdAt":  {
          "type":   "date", 
          "format": "strict_date_optional_time||epoch_millis"
        }
      }
    }
  },

  "warmers" : {},

  "aliases" : {"events": {}}
}

Most helpful comment

The payload variable you listed isn't actually the payload sent to elasticsearch. As described in the api conventions document the payload/body is specified as the body: parameter to the client.

So I think what you meant to send was something like this:

var payload = {
  "settings": {
    "number_of_shards": 100,
    "number_of_replicas": 1
  },

  "mappings": {
    "event": { 
      "properties": { 
        "ip":       { "type": "string"  }, 
        "guid":     { "type": "string"  }, 
        "userId":   { "type": "string"  }, 
        "key":      { "type": "string"  }, 
        "value":    { "type": "string"  }, 
        "type":     { "type": "string"  }, 

        "campaign": { "type": "string"  }, 
        "source":   { "type": "string"  }, 
        "medium":   { "type": "string"  }, 
        "quantity": { "type": "double"  },

        "data":     { "type": "object"  },

        "createdAt":  {
          "type":   "date", 
          "format": "strict_date_optional_time||epoch_millis"
        }
      }
    }
  },

  "warmers" : {},

  "aliases" : {"events": {}}
};

var params = {
  "index": "events-2015-11",
  "body": payload
};

client.indices.create(params, callback)

>All comments

The payload variable you listed isn't actually the payload sent to elasticsearch. As described in the api conventions document the payload/body is specified as the body: parameter to the client.

So I think what you meant to send was something like this:

var payload = {
  "settings": {
    "number_of_shards": 100,
    "number_of_replicas": 1
  },

  "mappings": {
    "event": { 
      "properties": { 
        "ip":       { "type": "string"  }, 
        "guid":     { "type": "string"  }, 
        "userId":   { "type": "string"  }, 
        "key":      { "type": "string"  }, 
        "value":    { "type": "string"  }, 
        "type":     { "type": "string"  }, 

        "campaign": { "type": "string"  }, 
        "source":   { "type": "string"  }, 
        "medium":   { "type": "string"  }, 
        "quantity": { "type": "double"  },

        "data":     { "type": "object"  },

        "createdAt":  {
          "type":   "date", 
          "format": "strict_date_optional_time||epoch_millis"
        }
      }
    }
  },

  "warmers" : {},

  "aliases" : {"events": {}}
};

var params = {
  "index": "events-2015-11",
  "body": payload
};

client.indices.create(params, callback)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

selvakn picture selvakn  路  4Comments

bttf picture bttf  路  4Comments

shenieee09 picture shenieee09  路  4Comments

peshrawahmed picture peshrawahmed  路  3Comments

loretoparisi picture loretoparisi  路  3Comments