opensearch-php icon indicating copy to clipboard operation
opensearch-php copied to clipboard

[FEATURE] How to use indices()->putTemplate parameter

Open DIU-marc opened this issue 2 years ago • 4 comments

Hi there,

I am trying to create an Index Template via the SDK. As I can't find any documentation about, how do I use the method - the main question is: How must the parameter array be structured? Using the structure as of https://opensearch.org/docs/latest/im-plugin/index-templates/

as "body", i am getting always the error "No alive nodes found in your cluster". While creating an Index works.

A little documentation about would be very nice. And i hope somebody maybe has an example how to structure. This is my current structure (properties are added dynamically):

$indexTemplate = [ 'name' => 'Index Template', 'body' => [ 'index_patterns' => [ 'entity-v1-*' ], 'template' => [ 'settings' => [ 'number_of_shards' => $openSearchConfig['number_of_shards'], 'number_of_replicas' => $openSearchConfig['number_of_replicas'] ], 'mappings' => [ 'properties' => [] ] ], 'priority' => 200, 'version' => 1, '_meta' => [ 'description' => 'My Fancy Template.' ] ] ];

I also tried some ways I found for ElasticSearch - without any success. Would be great to get some unterstandings :) Thanks in advance!

DIU-marc avatar Mar 02 '24 09:03 DIU-marc

Solved with that structure

[ 'name' => 'foobar', 'body' => [ "index_patterns" => [ "logs-2020-01-*" ], "template" => [ "aliases" => [ "my_logs" => [ ] ], "settings" => [ "number_of_shards" => 2, "number_of_replicas" => 0 ], "mappings" => [ "properties" => [ "timestamp" => [ "type" => "date", "format" => "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" ], "value" => [ "type" => "double" ] ] ] ] ] ]

DIU-marc avatar Mar 02 '24 09:03 DIU-marc

We started adding guides and samples to various clients. @DIU-marc want to help? You could write a guide and a working sample for index templates. Something similar to https://github.com/opensearch-project/opensearch-py/blob/main/guides/index_template.md?

dblock avatar Mar 04 '24 21:03 dblock

Hi @dblock Thanks for your reply. Sure, would be glad to do that.

DIU-marc avatar Mar 07 '24 11:03 DIU-marc

Hello @DIU-marc,

I hope you're doing well. Whenever you find a moment, would you mind considering contributing by adding a guide?

Thank you!

saimedhi avatar May 23 '24 10:05 saimedhi