'mappings'에 해당되는 글 7건

  1. 2018.12.19 [Elasticsearch] Settings/Mappings 테스트 템플릿
  2. 2018.07.04 [Elasticsearch] 그냥 settings, mappings, template 예제
  3. 2016.03.02 [Elasticsearch] Create Index Settings & Mappings 템플릿.
  4. 2014.07.02 [Elasticsearch] mapping type 템플릿 (numeric, string, date)
  5. 2014.01.15 [elasticsearch] mapping field type 샘플.
  6. 2014.01.07 [elasticsearch] settings & mappings 샘플용 코드...
  7. 2013.04.08 [elasticsearch] Java API : Index

[Elasticsearch] Settings/Mappings 테스트 템플릿

Elastic/Elasticsearch 2018. 12. 19. 09:46

그냥 뭐 급하게 테스트 할 때 필요해서 올려 놓고 쓰려고 합니다.

(git 에 올리면 될 것을 ㅡ.ㅡ;;)


http://localhost:9200/helloworld

{

    "settings": {

        "index": {

            "number_of_shards": 1,

            "number_of_replicas": 0,

            "analysis": {

                "analyzer": {

                    "custom_analyzer": {

                        "tokenizer": "standard",

                        "filter": [

                            "lowercase",

                            "trim",

                            "custom_synonym"

                        ]

                    },

                    "cnori_analyzer" : {

                    "type" : "custom",

                    "tokenizer" : "cnori_tokenizer"

                    }

                },

                "tokenizer" : {

                "cnori_tokenizer" : {

                "type": "nori_tokenizer",

            "decompound_mode": "mixed"

                }

                },

                "filter": {

                    "custom_synonym": {

                        "type": "synonym_graph",

                        "synonyms": []

                    }

                }

            }

        }

    },

    "mappings": {

        "_doc": {

            "properties": {

                "title": {

                    "type": "text",

                    "analyzer" : "cnori_analyzer",

                    "fielddata" : true

                },

                "name": {

                    "type": "keyword"

                },

                "age": {

                    "type": "integer"

                },

                "created": {

                    "type": "date",

                    "format": "strict_date_optional_time||epoch_millis"

                }

            }

        }

    }

}



:

[Elasticsearch] 그냥 settings, mappings, template 예제

Elastic/Elasticsearch 2018. 7. 4. 14:05


[Settings]

"settings":{

  "number_of_shards":1,

  "number_of_replicas":0,

  "index.refresh_interval":"1h",

  "index.routing.allocation.require.box_type":"indexing",

  "index.similarity.default.type":"BM25",

  "index":{

    "analysis":{

      "analyzer":{

        "arirang_custom_analyzer":{

          "tokenizer":"arirang_tokenizer",

          "filter":[

              "lowercase",

              "trim",

              "arirang_synonym",

              "arirang_filter"

            ]

          }

      },

      "filter":{

        "arirang_synonym":{

            "type":"synonym_graph",

            "synonyms":[]

          }

        }

      }

  }

}


[Mappings]

"mappings" : {

  "product": {

    "_source": {

      "enabled": true

    },

    "dynamic_templates": [

      {

        "strings": {

          "match_mapping_type": "string",

          "mapping": {

            "type": "text",

            "analyzer": "arirang_custom_analyzer",

              "fields": {

                "raw": {

                  "type":  "keyword",

                  "ignore_above": 50

                }

            }

          }

        }

      }

    ]

  }

}


:

[Elasticsearch] Create Index Settings & Mappings 템플릿.

Elastic/Elasticsearch 2016. 3. 2. 12:30

그냥 복습 하는 차원에서 기록 합니다.



$ curl -XPUT "http://localhost:9200/INDEX_NAME" -d'

{

  "settings": {

  ...설정할 정보를 넣으세요...

  },

  "mapping": {

  ...설정할 정보를 넣으세요...

  }

}


별 내용 없습니다.

그냥 rest api를 이용해서 index 생성 할 때 필요한 설정 정보를 작성하는 틀 정도 입니다.

type 정보는 mappings 안에 넣으시면 됩니다.

기본적으로 해당 설정은 지정한 INDEX_NAME 에 한해서 적용되는 것입니다. 별도의 global 설정을 하고 싶으시다면 template 기능을 활용하시기 바랍니다.


참고링크)

:

[Elasticsearch] mapping type 템플릿 (numeric, string, date)

Elastic/Elasticsearch 2014. 7. 2. 15:49

# numeric type

"" : {"type" : "long", "store" : "no", "index" : "not_analyzed", "index_options" : "docs", "ignore_malformed" : true, "include_in_all" : false},

"" : {"type" : "long", "store" : "yes", "index" : "no", "index_options" : "docs", "ignore_malformed" : true, "include_in_all" : false},


# date type

"" : {"type" : "date", "format" : "yyyyMMddHHmmss", "store" : "no", "index" : "not_analyzed", "index_options" : "docs", "ignore_malformed" : true, "include_in_all" : false},

"" : {"type" : "date", "format" : "yyyyMMddHHmmss", "store" : "yes", "index" : "no", "index_options" : "docs", "ignore_malformed" : true, "include_in_all" : false},


# string type

"" : {"type" : "string", "store" : "no", "index" : "not_analyzed", "norms": {"enabled" : false}, "index_options" : "docs", "include_in_all" : false},

"" : {"type" : "string", "store" : "yes", "index" : "no", "include_in_all" : false},

:

[elasticsearch] mapping field type 샘플.

Elastic/Elasticsearch 2014. 1. 15. 15:48

field type mapping 할 때 매번 작성하기 귀찮아서 그냥 참고용으로 가장 많이 쓰는 옵션만 적어 봅니다.


- number type index not_analyzed
{"type" : "long", "store" : "no", "index" : "not_analyzed", "index_options" : "docs", "ignore_malformed" : true, "include_in_all" : false}

- number type index no
{"type" : "long", "store" : "yes", "index" : "no", "ignore_malformed" : true, "include_in_all" : false}

- string type index analyzed
{"type" : "string", "store" : "no", "index" : "analyzed", "omit_norms" : false, "index_options" : "offsets", "term_vector" : "with_positions_offsets", "include_in_all" : false}

- string type index not_analyzed
{"type" : "string", "store" : "no", "index" : "not_analyzed", "omit_norms" : true, "index_options" : "docs", "include_in_all" : false}

- string type index no
{"type" : "string", "store" : "yes", "index" : "no", "include_in_all" : false}

- boolean type index yes
{"type" : "boolean", "store" : "yes", "include_in_all" : false}

- boolean type index no
{"type" : "boolean", "store" : "yes", "index" : "no", "include_in_all" : false}


참고 URL : http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html

:

[elasticsearch] settings & mappings 샘플용 코드...

Elastic/Elasticsearch 2014. 1. 7. 18:41

그냥 참고용으로 올려 놓는 것입니다.

각 속성들은 서비스 특성에 맞춰서 설정 하시는게 좋습니다.


http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-update-settings.html

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-put-mapping.html

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html


{
    "settings" : {
        "number_of_shards" : 5,
        "number_of_replicas" : 0,
        "index" : {
            "refresh_interval" : "1s",
            "merge" : {
                "policy" : { "segments_per_tier" : 5 }
            },
            "analysis" : {
                "analyzer" : {
                    "analyzer_standard" : {
                        "type" : "standard",
                        "tokenizer" : "whitespace",
                        "filter" : ["lowercase", "trim"]
                    },
                    "analyzer_pattern" : {
                        "type" : "custom",
                        "tokenizer" : "tokenizer_pattern",
                        "filter" : ["lowercase", "trim"]
                    },
                    "analyzer_ngram" : {
                        "type" : "custom",
                        "tokenizer" : "tokenizer_ngram",
                        "filter" : ["lowercase", "trim"]
                    }
                },
                "tokenizer" : {
                    "tokenizer_ngram" : {
                        "type" : "nGram",
                        "min_gram" : "2",
                        "max_gram" : "10",
                        "token_chars": [ "letter", "digit" ]
                    },
                    "tokenizer_pattern" : {
                        "type" : "pattern",
                        "pattern" : ","
                    }
                }
            },
            "store" : {
                "type" : "mmapfs",
                "compress" : {
                    "stored" : true,
                    "tv" : true
                }
            }
        }
    },
    "mappings" : {
        "INDICE_TYPE_NAME" : {
            "_id" : {
                "index" : "not_analyzed",
                "path" : "KEY_FIELD_NAME"
            },
            "_source" : {
                "enabled" : "true"
            },
            "_all" : {
                "enabled" : "false"
            },
            "_boost" : {
                "name" : "_boost",
                "null_value" : 1.0
            },
            "analyzer" : "analyzer_standard",
            "index_analyzer" : "analyzer_standard",
            "search_analyzer" : "analyzer_standard",
            "properties" : {
                "LONG_KEY_FIELD" : {"type" : "long", "store" : "no", "index" : "not_analyzed",  "omit_norms" : true, "index_options" : "docs", "ignore_malformed" : true, "include_in_all" : false},
                "STRING_SEARCH_FIELD" : {"type" : "string", "store" : "no", "index" : "analyzed", "omit_norms" : false, "index_options" : "offsets", "term_vector" : "with_positions_offsets", "include_in_all" : false},
                "STRING_VIEW_FIELD" : {"type" : "string", "store" : "yes", "index" : "no", "include_in_all" : false},
                "INTEGER_KEY_FIELD" : {"type" : "integer", "store" : "no", "index" : "not_analyzed",  "omit_norms" : true, "index_options" : "docs", "ignore_malformed" : true, "include_in_all" : false},
                "FLOAT_KEY_FIELD" : {"type" : "float", "store" : "no", "index" : "not_analyzed", "omit_norms" : true, "index_options" : "docs", "ignore_malformed" : true, "include_in_all" : false},
                "LONG_VIEW_FIELD" : {"type" : "long", "store" : "yes", "index" : "no",  "ignore_malformed" : true, "include_in_all" : false},
                "STRING_KEY_FIELD" : {"type" : "string", "store" : "no", "index" : "not_analyzed", "omit_norms" : true, "index_options" : "docs", "include_in_all" : false},
                "NESTED_KEY_FIELD" : {"type" : "nested",
                "properties" : {
                    "STRING_KEY_FIELD" : {"type" : "string", "store" : "no", "index" : "not_analyzed", "omit_norms" : true, "index_options" : "docs", "include_in_all" : false},
                    "INTEGER_VIEW_FIELD" : {"type" : "integer", "store" : "yes", "index" : "no",  "ignore_malformed" : true, "include_in_all" : false}
                    }
                },
                "BOOLEAN_VIEW_FIELD" : {"type" : "boolean", "store" : "yes", "include_in_all" : false},
                "BOOLEAN_KEY_FIELD" : {"type" : "boolean", "store" : "no", "index" : "not_analyzed", "omit_norms" : true, "index_options" : "docs", "include_in_all" : false},
                "OBJECT_VIEW_FIELD" : {"type" : "object", "dynamic" : true, "store" : "yes", "index" : "no", "include_in_all" : false}
            }
        }
    }
}






:

[elasticsearch] Java API : Index

Elastic/Elasticsearch 2013. 4. 8. 18:42

본 문서는 개인적인 테스트와 elasticsearch.org 그리고 community 등을 참고해서 작성된 것이며,

정보 교환이 목적입니다.


잘못된 부분에 대해서는 지적 부탁 드립니다.

(예시 코드는 성능 및 보안 검증이 되지 않았습니다.)



[elasticsearch java api 리뷰]

원문 링크 : http://www.elasticsearch.org/guide/reference/java-api/index_/


json document 를 생성하는 몇 가지 방법을 설명하고 있습니다.

There are different way of generating JSON document:


- Manually (aka do it yourself) using native byte[] or as a String

- Using Map that will be automatically converted to its JSON equivalent

- Using a third party library to serialize your beans such as Jackson

- Using built-in helpers XContentFactory.jsonBuilder()


위 방법들 중에서 제일 아래 elasticsearch helper 를 이용한 방법을 테스트해 봅니다.


우선 간단하게 index 와 index type 을 정의해 보도록 하겠습니다.

curl -XPUT 'http://localhost:9200/facebook' -d '{

    "settings" : { 

        "number_of_shards" : 5,

        "number_of_replicas" : 1  

    },  

    "mappings" : { 

        "post" : { 

            "properties" : { 

                "docid" : { "type" : "string", "store" : "yes", "index" : "not_analyzed" },

                "title" : { "type" : "string", "store" : "yes", "index" : "analyzed", "term_vector" : "yes", "analyzer" : "standard" }

            }   

        }   

    }   

}'


- index 는 facebook 으로 생성을 하고

- index type 은 post 라고 생성을 합니다.

- settings 와 mappings 에 대한 상세한 내용은 아래 링크 참고 하시기 바랍니다.

http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index/

http://www.elasticsearch.org/guide/reference/index-modules/

http://www.elasticsearch.org/guide/reference/mapping/

http://www.elasticsearch.org/guide/reference/mapping/core-types/


index, index type 생성이 끝났으면 이제 색인을 해보도록 하겠습니다

// 생성할 문서가 아래와 같다고 가정

// curl -XPUT 'http://localhost:9200/facebook/post/1' -d '{ "docid" : "henry", "title" : "This is the elasticsearch hadoop test." }'

// curl -XPUT 'http://localhost:9200/facebook/post/2' -d '{ "docid" : "henry", "title" : "elasticsearch test." }'

// curl -XPUT 'http://localhost:9200/facebook/post/3' -d '{ "docid" : "howook", "title" : "hadoop test." }'

// curl -XPUT 'http://localhost:9200/facebook/post/4' -d '{ "docid" : "howook", "title" : "test." }'


    IndexRequestBuilder requestBuilder;

    IndexResponse response;

        

    requestBuilder = client.prepareIndex("facebook", "post");

        

// setSource parameter 로 json string 형태로 등록

    requestBuilder.setId("1");

    requestBuilder.setSource("{ \"docid\" : \"henry\", \"title\" : \"This is the elasticsearch hadoop test.\" }");

    response = requestBuilder.execute().actionGet();


// XContentBuilder 로 setSource 전달

    XContentBuilder jsonBuilderDocument = jsonBuilder().startObject();

        jsonBuilderDocument.field("docid", "henry");

        jsonBuilderDocument.field("title", "elasticsearch test.");

    jsonBuilderDocument.endObject();

        

    requestBuilder.setId("2");

    requestBuilder.setSource(jsonBuilderDocument);

    response = requestBuilder.execute().actionGet();


- IndexRequestBuilder 의 setSource 에 대한 코드를 보시면 어떤 arguments 받는지 알 수 있습니다.

- 그리고 문서 색인에 사용되는 여러가지 다양항 옵션들은 아래 링크를 참고 하시기 바랍니다.

http://www.elasticsearch.org/guide/reference/api/index_/


아래는 index 생성 시 필요한 settings 와 mappings 에 대한 예제 코드 입니다.

맛보기 참고용 입니다.

IndicesAdminClient indices = client.admin().indices();

CreateIndexRequest indexRequest = new CreateIndexRequest("INDEX_NAME");

    indexRequest

        .settings(jsonBuilderIndexSetting)

        .mapping("INDEX_TYPE_NAME", jsonBuilderIndiceSetting);

indices.create(indexRequest).actionGet();

- INDEX_NAME 은 생성한 index

- INDEX_TYPE_NAME 은 생성한 index type

- jsonBuilerIndexSetting 과 jsonBuilderIndiceSetting 은 XContentBuilder 객체

: