- 데이터 생성 # curl -X POST http://localhost:9200/classes/class/1/ -d '{"title":"Algorithm", "professor":"John"}'
* 오류 발생 * {"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}
* 해결 방안 * - POST 요청 Header에 Contet-Type Json 방식으로 변경 # curl -X POST http://localhost:9200/classes/class/1/ -H 'Content-Type: application/json' -d '{"title":"Algorithm", "professor":"John"}'
- 파일로 생성 # curl -X POST http://localhost:9200/classes/class/1/ -H 'Content-Type: application/json' -d @oneclass.json
- 데이터 업데이트 # curl -X POST http://localhost:9200/classes/class/1/_update?pretty -H 'Content-type: application/json' -d '{"doc": {"unit": 1}}' # curl -X PUT http://localhost:9200/classes/class/1/_update?pretty -H 'Content-type: application/json' -d '{"doc": {"unit": 1}}'
- 데이터 업데이트(Script) #curl -X POST http://localhost:9200/classes/class/1/_update?pretty -H 'Content-type: application/json' -d '{"script": "ctx._source.unit += 5"}'
3. Elasticsearch 데이터 Mapping
- 데이터 타입과 데이터 매칭을 시켜줍니다. (ex. text, int..) - 데이터 분석이나 시각화를 할 때 데이터 Mapping이 되어있는 데이터가 가공에 용이합니다. - 아래와 같이 초기 데이터 생성 시 mapping을 별도로 지정해주지 않으면 비어 있습니다. - Mapping 생성 # curl -X PUT 'http://localhost:9200/classes/class/_mapping?pretty' -H 'Content-Type: application/json' -d @classesRating_mapping.json
* 오류 발생 * Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true
* 해결 방안 * - 아래와 같이 include_type_name=true 옵션 추가 # curl -X PUT 'http://localhost:9200/classes/class/_mapping?include_type_name=true&pretty' -H 'Content-Type: application/json' -d @classesRating_mapping.json
* 오류 발생 * "No handler for type [string] declared on field [professor]"
* 해결 방안 * - 아래와 같이 string type을 text로 변경해줍니다. - 버전이 바뀌면서 type_name이 변경된 걸로 확인됩니다. # sed -i 's/string/text/g' classesRating_mapping.json