본문 바로가기

프로젝트/여행지 오픈 API

[ElasticSearch] 로그스태시 최종 삽입

목차

     

    로그스태시를 통해 5만여개의 데이터를 삽입하였다.

    빅데이터라고는 할 수 없지만, 900MB의 텍스트 데이터에서 유효한 토큰을 추출 할 수 있을 것이라고 기대해본다.

     

     

    그런데, 이렇게 넣는 데이터로 만들어지는 인덱스의 설정을 만들어지고 reindex로 만드는 것 보다는 인덱스 템플릿을 만들고 적용하는 것이 더욱 효율적일 것이다.

     

    숙박업소와 여행지의 템플릿을 설정하려고 한다.
    # 숙박업소
    PUT _index_template/scrap_template_accmmo
    {
      "index_patterns": ["scrap_accommo_*"],
      "template": {
        "settings": {
          "number_of_shards": 1,
          "analysis": {
          "analyzer": {
            "korean": {
              "type": "custom",
              "tokenizer": "nori_tokenizer",
              "filter": ["nori_readingform"]
            }
          }
        }
      },
        "mappings": {
            "properties" : {
              "id" : {"type" : "keyword"},
              "pk_id" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              },
              "accommodation_addr" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              },
              "accommodation_lat" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              },
              "accommodation_lng" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              },
              "accommodation_name" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              },
              "accommodation_pic" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              },
              "accommodation_price" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              },
              "accommodation_score" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              },
              "accommodation_type" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              }
            }
        }
      }
    }
    
    # 여행정보
    PUT _index_template/scrap_template_wiki
    {
      "index_patterns": ["scrap_wiki_*"],
      "template": {
        "settings": {
          "number_of_shards": 1,
          "analysis": {
          "analyzer": {
            "korean": {
              "type": "custom",
              "tokenizer": "nori_tokenizer",
              "filter": ["nori_readingform"]
            }
          }
        }
      },
        "mappings": {
            "properties" : {
              "id" : {"type" : "keyword"},
              "content_id" : {"type" : "keyword"},
              "pk_id" : {"type" : "keyword"},
              "number" : {"type" : "keyword"},
              "attraction_name" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              },
              "wiki_title" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              },
              "wiki_content" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              }
            }
        }
      }
    }