Elastic basic #2 - 인덱스 생성 (mapping)
#!/bin/bash
curl -X PUT 'http://192.168.147.128:9200/superman?pretty' -H 'Content-Type: application/json' -d '
{
"settings" : {
"number_of_shards" : 3,
"number_of_replicas" : 1
},
"mappings" : {
"doc" : {
"properties" : {
"x" : { "type" : "integer" }
}
}
}
}'
===========================================
index 생성이 잘되었는지 확인
$ curl -X GET http://192.168.147.128:9200/superman?pretty
{
"superman" : {
"aliases" : { },
"mappings" : {
"doc" : {
"properties" : {
"x" : {
"type" : "integer"
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1555574029883",
"number_of_shards" : "3",
"number_of_replicas" : "1",
"uuid" : "dXHMdpSCQyai3nsPKdevJw",
"version" : {
"created" : "6060299"
},
"provided_name" : "superman"
}
}
}
}
===========================================
데이터 삽입
/**
임의의 id로 document를 생성하라면 curl 명령어의 메서드가 post 여야만 정상적으로 실행되고 put 메서드로는 정상적으로 실행되지 않는다.
*/
#!/bin/bash
curl -X PUT 'http://192.168.147.128:9200/superman/doc/1?pretty' -H 'Content-Type: application/json' -d '
{
"x" : 1
}'
#!/bin/bash
curl -X POST 'http://192.168.147.128:9200/superman/doc?pretty' -H 'Content-Type: application/json' -d '
{
"x" : 10
}'
===========================================
전체 데이터 조회
$ curl -X GET http://192.168.147.128:9200/superman/_search?pretty