본문 바로가기

IT/elasticsearch

인덱스 생성

{

  "settings" : {"number_of_shards":2,"number_of_replicas":1},

  "mappings": {

    "post": {

      "_source" : { "enabled" : false},

      "properties": {

        "id": {"type":"long", "store":"yes", "precision_step":"8" },

        "name": {"type":"string", "store":"yes", "index":"analyzed" },

        "published": {"type":"date", "store":"yes", "precision_step":"8" },

        "contents": {"type":"string", "store":"no", "index":"analyzed" }

      }

    }

  }

}


매핑할때 _soruce 필드가 disbaled 상태에서,

프로퍼티중 stored 필드가  no 라면 검색결과에서  해당 값을 볼 수 없다.  

다만 index 는 analyzed 로 되어 있기 때문에 해당 필드로 검색은 가능하다.


예제 데이터 (post로 보내야한다. 랜덤 id )

http://172.30.16.44:9200/posts/post

{

  "id":999999999,

  "contents":"Elasticsearch",

  "name" : "metdoloca",

  "published" : "2015-09-09"

}




contents 필드가 "ela" 로 시작하는 도큐먼트를 찾고, 리턴 필드를 contents 로 명시했지만....

contents 내용이 리턴되지 않았다.. 검색으로 사용 가능하자만, 리턴은 안된다.


http://172.30.16.44:9200/posts/post/_search?pretty&q=contents:ela*&fields=contents




"hits" : [ {
      "_index" : "posts",
      "_type" : "post",
      "_id" : "AVBQqx8tUTQjXcVPVqLP",
      "_score" : 1.0
    } ]

부분 필드 리턴은 반드시 _source 필드를 enable 시켜야 함


'IT > elasticsearch' 카테고리의 다른 글

relocate index and log path problem  (0) 2017.12.05
텔레그램 봇 만들기  (0) 2016.03.28
logstash.conf  (0) 2015.10.31
logstash-forwarder 설정  (0) 2015.10.31