ELASTICSEARCH Mapping

ELASTICSEARCH Mapping

RDB's Schema. 효율적인 검색을 위해서 데이터의 타입을 정의하는 것

Step 1. Create Index

curl -XPUT localhost:9200/classes

Error

{
  "error": {
    "root_cause": [
      {
        "type": "index_already_exists_exception",
        "reason": "index [classes/5mBFGPEwRpOdJP08VNDJug] already exists",
        "index_uuid": "5mBFGPEwRpOdJP08VNDJug",
        "index": "classes"
      }
    ],
    "type": "index_already_exists_exception",
    "reason": "index [classes/5mBFGPEwRpOdJP08VNDJug] already exists",
    "index_uuid": "5mBFGPEwRpOdJP08VNDJug",
    "index": "classes"
  },
  "status": 400
}
curl -XDELETE localhost:9200/classes
curl -XPUT localhost:9200/classes

Success

{
  "classes" : {
    "aliases" : { },
    "mappings" : { },
    "settings" : {
      "index" : {
        "creation_date" : "1493388598544",
        "number_of_shards" : "5",
        "number_of_replicas" : "1",
        "uuid" : "N2GHTYgFQqOy_DoP9zuISA",
        "version" : {
          "created" : "5030199"
        },
        "provided_name" : "classes"
      }
    }
  }
}

Mapping 없이 Index만 생성했기 때문에, classes.mappings 의 값이 빈 객체이다.

Step 2. Create Mapping

2-1 Get classesRating_mapping.json

wget https://raw.githubusercontent.com/minsuk-heo/BigData/master/ch02/classesRating_mapping.json

2-2 Mapping

curl -XPUT localhost:9200/classes/class/_mapping -d @classesRating_mapping.json

2-3 Verify Mapping

curl -XGET localhost:9200/classes?pretty
Success
{
  "classes" : {
    "aliases" : { },
    "mappings" : {
      "class" : {
        "properties" : {
          "major" : {
            "type" : "text"
          },
          "professor" : {
            "type" : "text"
          },
          "rating" : {
            "type" : "integer"
          },
          "school_location" : {
            "type" : "geo_point"
          },
          "semester" : {
            "type" : "text"
          },
          "student_count" : {
            "type" : "integer"
          },
          "submit_date" : {
            "type" : "date",
            "format" : "yyyy-MM-dd"
          },
          "title" : {
            "type" : "text"
          },
          "unit" : {
            "type" : "integer"
          }
        }
      }
    },
    "settings" : {
      "index" : {
        "creation_date" : "1493388598544",
        "number_of_shards" : "5",
        "number_of_replicas" : "1",
        "uuid" : "N2GHTYgFQqOy_DoP9zuISA",
        "version" : {
          "created" : "5030199"
        },
        "provided_name" : "classes"
      }
    }
  }
}

2-4 Add Documents

wget https://raw.githubusercontent.com/minsuk-heo/BigData/master/ch02/classes.json
curl -XPOST localhost:9200/_bulk?pretty --data-binary @classes.json
Verify Documents
curl -XGET localhost:9200/classes/class/1?pretty

results matching ""

    No results matching ""