Skip to content

Commit

Permalink
minor doc fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lmouhib committed Nov 18, 2024
1 parent d79f273 commit 680b1f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ExampleOpenSearchApiStack extends cdk.Stack {
openSearchClusterType:dsf.consumption.OpenSearchClusterType.PROVISIONED,
removalPolicy:cdk.RemovalPolicy.DESTROY
});
/// !hide
//Add another admin
osApi.addRoleMapping('AnotherAdmin', 'all_access','sometestId');

Expand Down Expand Up @@ -64,7 +65,7 @@ class ExampleOpenSearchApiStack extends cdk.Stack {
add2Cr.node.addDependency(indexTemplateCr);
const add3Cr = osApi.callOpenSearchApi('AddData4', 'movies-01/_doc',{"title": "The Little Mermaid", "year": 2015}, 'POST');
add3Cr.node.addDependency(indexTemplateCr);
/// !hide


}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,59 +14,14 @@ The construct leverages the [CDK Provider Framework](https://docs.aws.amazon.com
<TabItem value="typescript" label="TypeScript" default>

```typescript
const domainEndpoint='search-XXXXXX.XXXXXX.es.amazonaws.com';
const apiRole = Role.fromRoleName(this, 'ApiRole', '<IAMRoleWithOpenSearchPermissions>');
const osApi = new dsf.consumption.OpenSearchApi(this, 'MyOpenSearchApi',{
iamHandlerRole:apiRole,
openSearchEndpoint:domainEndpoint,
openSearchClusterType:dsf.consumption.OpenSearchClusterType.PROVISIONED,
removalPolicy:cdk.RemovalPolicy.DESTROY
});
//Add another admin
osApi.addRoleMapping('AnotherAdmin', 'all_access','sometestId');

//create index template
const indexTemplateCr = osApi.callOpenSearchApi('CreateIndexTemplate','_index_template/movies',
{
"index_patterns": [
"movies-*"
],
"template": {
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 0
}
},
"mappings": {
"properties": {
"title": {
"type": "text"
},
"year": {
"type": "integer"
}
}
}
}
});
const metadata='{ "index" : { "_index" : "movies-02"}}';
const bulk=`${metadata}
{"title": "Barbie", "year": 2023}
${metadata}
{"title": "Openheimer", "year": 2023}`;

// bulk ingestion using POST
const bulkCr = osApi.callOpenSearchApi('AddBulk','_bulk',bulk+'\n\n','POST');
//dependency to enforce sequential API calls
bulkCr.node.addDependency(indexTemplateCr);

const add1Cr = osApi.callOpenSearchApi('AddData1', 'movies-01/_doc/1111',{"title": "Rush", "year": 2013}, 'PUT');
add1Cr.node.addDependency(indexTemplateCr);
const add2Cr = osApi.callOpenSearchApi('AddData3', 'movies-01/_doc/2222',{"title": "Toy Story", "year": 2014}, 'PUT');
add2Cr.node.addDependency(indexTemplateCr);
const add3Cr = osApi.callOpenSearchApi('AddData4', 'movies-01/_doc',{"title": "The Little Mermaid", "year": 2015}, 'POST');
add3Cr.node.addDependency(indexTemplateCr);
const domainEndpoint='search-XXXXXX.XXXXXX.es.amazonaws.com';
const apiRole = Role.fromRoleName(this, 'ApiRole', '<IAMRoleWithOpenSearchPermissions>');
const osApi = new dsf.consumption.OpenSearchApi(this, 'MyOpenSearchApi',{
iamHandlerRole:apiRole,
openSearchEndpoint:domainEndpoint,
openSearchClusterType:dsf.consumption.OpenSearchClusterType.PROVISIONED,
removalPolicy:cdk.RemovalPolicy.DESTROY
});
```

</TabItem>
Expand All @@ -81,49 +36,6 @@ os_api = dsf.consumption.OpenSearchApi(self, "MyOpenSearchApi",
open_search_cluster_type=dsf.consumption.OpenSearchClusterType.PROVISIONED,
removal_policy=cdk.RemovalPolicy.DESTROY
)
# Add another admin
os_api.add_role_mapping("AnotherAdmin", "all_access", "sometestId")

# create index template
index_template_cr = os_api.call_open_search_api("CreateIndexTemplate", "_index_template/movies", {
"index_patterns": ["movies-*"
],
"template": {
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 0
}
},
"mappings": {
"properties": {
"title": {
"type": "text"
},
"year": {
"type": "integer"
}
}
}
}
})
metadata = "{ \"index\" : { \"_index\" : \"movies-02\"}}"
bulk = f"""{metadata}
{\"title\": \"Barbie\", \"year\": 2023}
{metadata}
{\"title\": \"Openheimer\", \"year\": 2023}"""

# bulk ingestion using POST
bulk_cr = os_api.call_open_search_api("AddBulk", "_bulk", bulk + "\n\n", "POST")
# dependency to enforce sequential API calls
bulk_cr.node.add_dependency(index_template_cr)

add1_cr = os_api.call_open_search_api("AddData1", "movies-01/_doc/1111", {"title": "Rush", "year": 2013}, "PUT")
add1_cr.node.add_dependency(index_template_cr)
add2_cr = os_api.call_open_search_api("AddData3", "movies-01/_doc/2222", {"title": "Toy Story", "year": 2014}, "PUT")
add2_cr.node.add_dependency(index_template_cr)
add3_cr = os_api.call_open_search_api("AddData4", "movies-01/_doc", {"title": "The Little Mermaid", "year": 2015}, "POST")
add3_cr.node.add_dependency(index_template_cr)
```

</TabItem>
Expand Down

0 comments on commit 680b1f9

Please sign in to comment.