https://docs.aws.amazon.com/ja_jp/opensearch-service/latest/developerguide/gsg.html
https://dev.classmethod.jp/articles/getting-started-amazon-opensearch-service/
-- 1. コマンド等のインストール
-- 1.1 aws cli version 2 インストール
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version
-- 1.2 jqインストール
sudo yum -y install jq
-- 2. ドメインの作成
aws opensearch create-domain \
--domain-name domain01 \
--engine-version OpenSearch_1.3 \
--cluster-config '{
"InstanceType": "t3.small.search",
"InstanceCount": 1,
"DedicatedMasterEnabled": false,
"ZoneAwarenessEnabled": false,
"WarmEnabled": false,
"ColdStorageOptions": {
"Enabled": false
}
}' \
--ebs-options '{
"EBSEnabled": true,
"VolumeType": "gp3",
"VolumeSize": 10,
"Iops": 3000,
"Throughput": 125
}' \
--access-policies "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":\"es:*\",\"Resource\":\"arn:aws:es:ap-northeast-1:999999999999:domain/domain01/*\"}]}" \
--snapshot-options '{
"AutomatedSnapshotStartHour": 0
}' \
--vpc-options '{
"SubnetIds": [
"subnet-11111111111111111"
],
"SecurityGroupIds": [
"sg-22222222222222222"
]
}' \
--cognito-options '{
"Enabled": false
}' \
--encryption-at-rest-options '{
"Enabled": true,
"KmsKeyId": "arn:aws:kms:ap-northeast-1:999999999999:key/33333333-3333-3333-3333-333333333333"
}' \
--node-to-node-encryption-options '{
"Enabled": true
}' \
--advanced-options '{
"indices.fielddata.cache.size": "20",
"indices.query.bool.max_clause_count": "1024",
"override_main_response_version": "false",
"rest.action.multi.allow_explicit_index": "true"
}' \
--domain-endpoint-options '{
"EnforceHTTPS": true,
"TLSSecurityPolicy": "Policy-Min-TLS-1-0-2019-07",
"CustomEndpointEnabled": false
}' \
--advanced-security-options '{
"Enabled": true,
"InternalUserDatabaseEnabled": true,
"MasterUserOptions": {
"MasterUserName": "root",
"MasterUserPassword": "password"
},
"AnonymousAuthEnabled": false
}' \
--auto-tune-options '{
"DesiredState": "ENABLED",
"MaintenanceSchedules": []
}'
aws opensearch list-domain-names
aws opensearch describe-domain \
--domain-name domain01
aws opensearch describe-domain-config \
--domain-name domain01
-- 3. インデックス作成のためにデータをアップロードする
curl -XPUT -u 'root:password' 'https://vpc-domain01-44444444444444444444444444.ap-northeast-1.es.amazonaws.com/movies/_doc/1' -d '{"director": "Burton, Tim", "genre": ["Comedy","Sci-Fi"], "year": 1996, "actor": ["Jack Nicholson","Pierce Brosnan","Sarah Jessica Parker"], "title": "Mars Attacks!"}' -H 'Content-Type: application/json'
{ "index" : { "_index": "movies", "_id" : "2" } }
{"director": "Frankenheimer, John", "genre": ["Drama", "Mystery", "Thriller", "Crime"], "year": 1962, "actor": ["Lansbury, Angela", "Sinatra, Frank", "Leigh, Janet", "Harvey, Laurence", "Silva, Henry", "Frees, Paul", "Gregory, James", "Bissell, Whit", "McGiver, John", "Parrish, Leslie", "Edwards, James", "Flowers, Bess", "Dhiegh, Khigh", "Payne, Julie", "Kleeb, Helen", "Gray, Joe", "Nalder, Reggie", "Stevens, Bert", "Masters, Michael", "Lowell, Tom"], "title": "The Manchurian Candidate"}
{ "index" : { "_index": "movies", "_id" : "3" } }
{"director": "Baird, Stuart", "genre": ["Action", "Crime", "Thriller"], "year": 1998, "actor": ["Downey Jr., Robert", "Jones, Tommy Lee", "Snipes, Wesley", "Pantoliano, Joe", "Jacob, Ir\u00e8ne", "Nelligan, Kate", "Roebuck, Daniel", "Malahide, Patrick", "Richardson, LaTanya", "Wood, Tom", "Kosik, Thomas", "Stellate, Nick", "Minkoff, Robert", "Brown, Spitfire", "Foster, Reese", "Spielbauer, Bruce", "Mukherji, Kevin", "Cray, Ed", "Fordham, David", "Jett, Charlie"], "title": "U.S. Marshals"}
{ "index" : { "_index": "movies", "_id" : "4" } }
{"director": "Ray, Nicholas", "genre": ["Drama", "Romance"], "year": 1955, "actor": ["Hopper, Dennis", "Wood, Natalie", "Dean, James", "Mineo, Sal", "Backus, Jim", "Platt, Edward", "Ray, Nicholas", "Hopper, William", "Allen, Corey", "Birch, Paul", "Hudson, Rochelle", "Doran, Ann", "Hicks, Chuck", "Leigh, Nelson", "Williams, Robert", "Wessel, Dick", "Bryar, Paul", "Sessions, Almira", "McMahon, David", "Peters Jr., House"], "title": "Rebel Without a Cause"}
curl -XPOST -u 'root:password' 'https://vpc-domain01-44444444444444444444444444.ap-northeast-1.es.amazonaws.com/_bulk' --data-binary @bulk_movies.json -H 'Content-Type: application/json'
-- 4. ドキュメントの検索
curl -XGET -u 'root:password' 'https://vpc-domain01-44444444444444444444444444.ap-northeast-1.es.amazonaws.com/movies/_search?q=mars&pretty=true'
curl -XGET -u 'root:password' 'https://vpc-domain01-44444444444444444444444444.ap-northeast-1.es.amazonaws.com/movies/_search?q=rebel&pretty=true'
-- 5. クリーンアップ
-- ドメインの削除
aws opensearch list-domain-names
aws opensearch delete-domain \
--domain-name domain01