Elasticsearchでインデックスを作成する
インデックスを作成するにあたり、mappingsやsettingsあたりを一緒に登録する方法。
インデックス作成
curl -H "Content-Type: application/json" -XPUT "http://localhost:9200/sample_index?pretty" -d ' { "settings": { "number_of_shards": 100 }, "mappings": { "properties": { "sample": { "type": "text" } } } } '
mappings確認
期待通りか確認する。
curl -XGET "http://localhost:9200/sample_index/_mappings?pretty" { "sample_index" : { "mappings" : { "properties" : { "sample" : { "type" : "text" } } } } }
大丈夫そう。
settings確認
次にsettingsも。
curl -XGET "http://localhost:9200/sample_index/_settings?pretty" { "sample_index" : { "settings" : { "index" : { "creation_date" : "1595507722172", "number_of_shards" : "100", "number_of_replicas" : "1", "uuid" : "lCuqDV3KQZi_YuwM-mfx4g", "version" : { "created" : "7080099" }, "provided_name" : "sample_index" } } } }
こちらも大丈夫そう。
最後に
データを投入するとmappingsは自動で作成されるが、事前に定義することも可能であることがわかった。 またsettingsについても定義できることがわかった。今後kuromojiを使用して形態素解析を行う予定なので、その場合はこちらにkuromojiを設定することになるので事前に素振りできてよかった。