skip to Main Content

I’ve configured Opensearch domain in AWS. As part of automating configurations in opensearch, I want to create a set of index patterns.

I’ve tried so many APIs available online, but could not succeed. Has anyone managed to create index pattern in AWS Opensearch?

2

Answers


  1. Chosen as BEST ANSWER

    I've figured it out,

    I used the python code provided by aws to create index patterns.

    https://repost.aws/knowledge-center/opensearch-index-pattern

    CURL command provided in the doc did not work as it gave me 404 not found error.

    Please note that if you are creating index patterns in custom domain, please pass the headers as securitytenant instead of security_tenant mentioned in doc.


  2. In my case (I use nodejs) I write typescript script which create opensearch index, I use @opensearch-project/opensearch npm package

    import { Client } from "@opensearch-project/opensearch";
    import { CampaignSearchIndex } from "../src/core/domain/indices";
    
    const openSearchClient = new Client({
      node: process.env.OPENSEARCH_DB_NODE as string,
      auth: {
        username: process.env.OPENSEARCH_DB_USERNAME as string,
        password: process.env.OPENSEARCH_DB_PASSWORD as string,
      },
    });
    openSearchClient.indices.create({
      index: CampaignSearchIndex.IndexName,
      body: {
        mappings: {
          ...CampaignSearchIndex.getMapping(),
        }
      },
    }).then(() => process.exit);
    

    this is example code for nodejs, you can implements functionality like this in python.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search