2.X/1. Getting Started

1-01-05. Indexing Employee Documents

drscg 2017. 10. 1. 12:19

The first order of business is storing employee data. This will take the form of an employee document: a single document represents a single employee. The act of storing data in Elasticsearch is called indexing, but before we can index a document, we need to decide where to store it.

첫 번째 요구사항은 직원 데이터를 저장하는 것이다. 이것은 employee document 의 형태를 가질 것이다. 하나의 document는 직원 1명을 나타낸다. Elasticsearch에 데이터를 저장하는 것을 색인한다(indexing) 라고 한다. 그러나, document를 색인하기 전에, 그것을 어디 에 저장할지를 결정해야 한다.

An Elasticsearch cluster can contain multiple indices, which in turn contain multiple types. These types hold multiple documents, and each document has multiple fields.

하나의 Elasticsearch cluster는 다수의 indices (databases) 를 가질 수 있고, 다시 indices는 다수의 types를 가질 수 있다. 이들 type은 다수의 documents 를 가지고 있고, 각 document는 다수의 fields (columns)를 가진다.

So for our employee directory, we are going to do the following:

이제, 우리의 직원 인명 사전을 위해 다음처럼 해 볼 것이다.

  • Index a document per employee, which contains all the details of a single employee.

    직원 별로 하나의 document 를 색인 한다. 이 document는 개별 직원의 모든 정보를 가지고 있다.

  • Each document will be of type employee.

    각 document는 employee 라는 type 에 포함될 것이다.

  • That type will live in the megacorp index.

    해당 type은 megacorp 라는 index 에 포함된다.

  • That index will reside within our Elasticsearch cluster.

    해당 index가 Elasticsearch cluster에 존재할 것이다.

In practice, this is easy (even though it looks like a lot of steps). We can perform all of those actions in a single command:

복잡해 보이지만 실제로 이것은 매우 쉽다. 이 모든 것을 명령어 하나로 실행할 수 있다.

PUT /megacorp/employee/1
{
    "first_name" : "John",
    "last_name" :  "Smith",
    "age" :        25,
    "about" :      "I love to go rock climbing",
    "interests": [ "sports", "music" ]
}

Notice that the path /megacorp/employee/1 contains three pieces of information:

/megacorp/employee/1 이라는 경로는 3가지 정보를 포함하고 있다는 것을 기억하자.

megacorp

The index name

index 이름

employee

The type name

type 이름

1

The ID of this particular employee

특정 직원의 ID

The request body—the JSON document—contains all the information about this employee. His name is John Smith, he’s 25, and enjoys rock climbing.

JSON Document로 이루어진 request body는 이 직원에 대한 모든 정보를 가지고 있다. 그의 이름은 John Smith, 25세이고 암벽타기를 즐겨 한다.

Simple! There was no need to perform any administrative tasks first, like creating an index or specifying the type of data that each field contains. We could just index a document directly. Elasticsearch ships with defaults for everything, so all the necessary administration tasks were taken care of in the background, using default values.

간단하다. 먼저 수행해야 할 index를 생성하거나 각 field가 가지고 있는 데이터의 타입을 지정하는 것과 같은, 관리 작업이 전혀 없다. 바로 document를 색인할 수 있다. Elasticsearch는 모든 것에 대해 기본값을 가진다. 따라서, 필요한 모든 관리 작업은, 기본 값을 사용하여, background에서 이루어진다.

Before moving on, let’s add a few more employees to the directory:

다음으로 가기 전에, 직원 인명 사전에 조금 더 직원을 추가하자.

PUT /megacorp/employee/2
{
    "first_name" :  "Jane",
    "last_name" :   "Smith",
    "age" :         32,
    "about" :       "I like to collect rock albums",
    "interests":  [ "music" ]
}

PUT /megacorp/employee/3
{
    "first_name" :  "Douglas",
    "last_name" :   "Fir",
    "age" :         35,
    "about":        "I like to build cabinets",
    "interests":  [ "forestry" ]
}


'2.X > 1. Getting Started' 카테고리의 다른 글

1-01-03. Document Oriented  (0) 2017.10.01
1-01-04. Finding Your Feet  (0) 2017.10.01
1-01-06. Retrieving a Document  (0) 2017.10.01
1-01-07. Search Lite  (0) 2017.10.01
1-01-08. Search with Query DSL  (0) 2017.10.01