BackEnd/Elasticsearch API

Mapping parameters

hanseom 2025. 3. 14. 02:00
반응형

index

  필드가 색인될지 여부를 결정합니다. 대부분의 필드 타입에서 기본적으로 활성화되어 있습니다. false일 경우 색인이 되지 않아 검색이 불가능합니다.

{
  "properties": {
    "session_data": {
      "type": "keyword",
      "index": false
    }
  }
}

 

analyzer

  텍스트 필드에 사용할 분석기를 지정합니다.

{
  "properties": {
    "title": {
      "type": "text",
      "analyzer": "english"
    }
  }
}

 

format

  날짜 필드에 사용되는 형식을 지정합니다.

{
  "properties": {
    "timestamp": {
      "type": "date",
      "format": "strict_date_optional_time||epoch_millis"
    }
  }
}

 

coerce

  데이터가 필드의 데이터 타입과 일치하지 않을 때 강제로 변환할지 여부를 결정합니다. 기본적으로 활성화되어 있습니다. 예를 들어, 숫자 필드에 문자열이 입력될 경우 자동으로 숫자로 변환합니다.

{
  "properties": {
    "age": {
      "type": "integer",
      "coerce": true
    }
  }
}

 

doc_values

  필드에 대해 doc_values를 활성화할지 여부를 결정합니다. 이는 정렬과 집계에 유용한 자료 구조를 제공합니다. 대부분의 필드 타입에서 기본적으로 활성화되어 있습니다. text와 annotated_text 필드에서는 지원되지 않습니다.

PUT /software_store
{
  "mappings": {
    "properties": {
      "product_name": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "price": {
        "type": "double",
        "doc_values": true
      },
      "release_date": {
        "type": "date",
        "doc_values": true
      },
      "price": {
        "type": "integer",
        "doc_values": true
      }
    }
  }
}

POST /software_store/_doc/1
{
  "product_name": "Elasticsearch Book",
  "price": 29.99,
  "release_date": "2023-01-01",
  "stock": 150
}

POST /software_store/_doc/2
{
  "product_name": "Kibana Dashboard",
  "price": 49.99,
  "release_date": "2023-05-15",
  "stock": 75
}

POST /software_store/_doc/3
{
  "product_name": "Logstash Guide",
  "price": 19.99,
  "release_date": "2023-03-10",
  "stock": 200
}

POST /software_store/_search
{
  "sort": [
    { "price": { "order": "asc" } }
  ],
  "_source": ["product_name", "price"]
}

 

norms

  문서의 점수를 계산하는 데 필요한 정규화 요인을 저장합니다. 이는 검색 시 문서의 관련성을 평가하는 데 사용됩니다. 기본적으로 활성화되어 있습니다. 그러나 디스크 공간을 많이 차지하므로 필터링이나 집계 전용 필드에서는 비활성화하는 것이 좋습니다.

{
  "properties": {
    "title": {
      "type": "text",
      "norms": false
    }
  }
}

 

null_value

  명시적인 null 값을 특정한 값으로 대체하여 색인 및 검색이 가능하도록 합니다. 다음은 status_code 필드의 null 값을 "NULL"로 대체하여 색인합니다.

{
  "properties": {
    "status_code": {
      "type": "keyword",
      "null_value": "NULL"
    }
  }
}

 

copy_to

  한 필드의 값을 다른 필드로 복사하여, 여러 필드를 하나의 필드로 통합하여 검색할 수 있게 합니다. 이는 검색 성능을 향상시키고, 여러 필드를 동시에 검색할 때 유용합니다.

PUT /name_book
{
  "mappings": {
    "properties": {
      "first_name": {
        "type": "text",
        "copy_to": "full_name"
      },
      "last_name": {
        "type": "text",
        "copy_to": "full_name"
      },
      "full_name": {
        "type": "text"
      },
      "email": {
        "type": "keyword"
      }
    }
  }
}

POST /name_book/_doc/1
{
  "first_name": "John",
  "last_name": "Doe",
  "email": "john.doe@example.com"
}

POST /name_book/_doc/2
{
  "first_name": "Jane",
  "last_name": "Smith",
  "email": "jane.smith@example.com"
}

POST /name_book/_search
{
  "query": {
    "match": {
      "full_name": "John Doe"
    }
  }
}

 

[참고자료]

반응형