본문으로 바로가기

Elasticsearch enabled index 옵션 차이

category ELK 2022. 9. 14. 19:00
반응형

2022.07.12 - [docker] - Docker + Elasticsearch, Kibana 구성 (single node)

 

Docker + Elasticsearch, Kibana 구성 (single node)

elasticsesarch, kibana 이미지 다운 및 컨테이너 실행 # elasticsearch 7.8.1 이미지 다운로드 docker pull docker.elastic.co/elasticsearch/elasticsearch:7.8.1 # elasticsearch 컨테이너 실행 # -d : detach..

1995-dev.tistory.com

"index" : {
    "mappings" : {
      "properties" : {
        "some_field1" : {
          "type" : "object",
          "enabled" : false
        }
        ...
enabled : <true | false>

- 인덱싱(역 색인)이 필요하지 않는 필드에 설정하는 옵션

- 최상위 매핑 정의 및 필드에만 적용할 수 있는 설정으로 type이 object

 

ES를 공부할때 인덱싱이 필요하지 않는 필드에 설정하는 옵션으로 index 옵션을 본적이 있어 두가지 차이점을 알아보려고 합니다.

index : <true | false>

 

my_index 입력

PUT my_index
{
  "mappings": {
    "properties": {
      "index_false": { 
        "index" : false,
        "type" : "keyword"
      },
      "enabled_false": { 
        "enabled" : false
      }
    }
  }
}

my_index mapping 정보

- enabled_false type object로 지정

# 조회
GET my_index/_mapping

# 결과
{
  "my_index" : {
    "mappings" : {
      "properties" : {
        "enabled_false" : {
          "type" : "object",
          "enabled" : false
        },
        "index_false" : {
          "type" : "keyword",
          "index" : false
        }
      }
    }
  }
}

데이터 입력

PUT my_index/_doc/1
{
  "index_false": "hello",
  "enabled_false": "hello"
}

index_false 조회

- index_false 조회 시 404 오류 발생

The index option controls whether field values are indexed. 
It accepts true or false and defaults to true. 
Fields that are not indexed are typically not queryable

이 index옵션은 필드 값이 인덱싱되는지 여부를 제어합니다.
true 또는 를 수락 false하며 기본값은 true입니다. 
인덱싱되지 않은 필드는 일반적으로 쿼리할 수 없습니다.
GET my_index/_search
{
  "query": {
    "match": {
      "index_false": "hello"
    }
  }
}

{
  "error" : {
    "root_cause" : [
      {
        "type" : "query_shard_exception",
        "reason" : "failed to create query: Cannot search on field [index_false] since it is not indexed.",
        "index_uuid" : "VS0LO8owQ2qICrKnV3ZVZA",
        "index" : "my_index"
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "my_index",
        "node" : "desyvkECQgq8d0kLQZNEpQ",
        "reason" : {
          "type" : "query_shard_exception",
          "reason" : "failed to create query: Cannot search on field [index_false] since it is not indexed.",
          "index_uuid" : "VS0LO8owQ2qICrKnV3ZVZA",
          "index" : "my_index",
          "caused_by" : {
            "type" : "illegal_argument_exception",
            "reason" : "Cannot search on field [index_false] since it is not indexed."
          }
        }
      }
    ]
  },
  "status" : 400
}

 

enabled_false 조회

- 오류 없이 실행, 색인되지 않아 결과 나오지 않음

GET my_index/_search
{
  "query": {
    "match": {
      "enabled_false": "hello"
    }
  }
}

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}

 

https://stackoverflow.com/questions/50836504/elasticsearch-mapping-parameters-index-vs-enabled

 

Elasticsearch mapping parameters : index vs enabled

I've been struggling with two elasticsearch mapping parameters: index and enabled. I'm using Elasticsearch 6.2.4. Here's my case. Mapping PUT my_index { "mappings": { "_doc": { "

stackoverflow.com

When settings enabled to false, you tell ES to completely ignore the parsing of the field, so it will neither be analyzed, nor indexed not stored (except in he _source field of course).
So, ES is not even aware that the field exists, and thus, it handles that case as if you were querying on any other non-existent field, basically as if the source didn't even contain the field. 
Result: ES doesn't return any document.
When setting index to false, ES is aware that the field exists (via the mapping), but it knows that it shouldn't be indexed. 
So when you query on it, ES tells you that you cannot do it since you've decided not to index that field. 
That's why ES throws an error since you're breaking the contract that you've declared in your mapping.

false로 설정하면 enabledES에게 필드의 구문 분석을 완전히 무시하도록 지시하므로 분석되지 않고 인덱싱되지도 않고 저장되지도 않습니다( _source물론 he 필드 제외).
따라서 ES는 필드가 존재한다는 사실조차 인식하지 못하므로 존재하지 않는 다른 필드에 대해 쿼리하는 것처럼, 기본적으로 소스에 필드가 포함되지 않은 것처럼 해당 경우를 처리합니다. 
결과: ES는 문서를 반환하지 않습니다.
false로 설정하면 indexES는 (매핑을 통해) 필드가 존재한다는 것을 인식하지만 인덱싱되어서는 안 된다는 것을 알고 있습니다. 
그래서 당신이 그것에 대해 쿼리할 때, ES는 당신이 그 필드를 인덱싱하지 않기로 결정했기 때문에 당신이 그것을 할 수 없다고 알려줍니다. 
이것이 매핑에서 선언한 계약을 위반했기 때문에 ES에서 오류가 발생하는 이유입니다.

위에 내용을 정리해보면 오류가 나는건 ES에서 해당 필드의 존재 유무를 인식하는지 차이가 있는거 같다.

 

 

https://www.elastic.co/guide/en/elasticsearch/reference/current/enabled.html

 

enabled | Elasticsearch Guide [8.4] | Elastic

Elasticsearch tries to index all of the fields you give it, but sometimes you want to just store the field without indexing it. For instance, imagine that you are using Elasticsearch as a web session store. You may want to index the session ID and last upd

www.elastic.co

반응형