2015-01-07 3 views
0

내 인덱스의 elasticsearch에서 기본 매핑을 업데이트하고 싶습니다. 그러나 모든 문서는 매핑을 업데이트하기위한 유형을 제공해야한다고 지적합니다. 문제는 많은 인덱스 유형이 있고 새로운 유형의 문서가 나타날 때처럼 동적으로 생성된다는 것입니다. 따라서 가장 좋은 방법은 기본 매핑 유형입니다. 각 유형에 대한 매핑을 정의하지 않아도됩니다. 하지만 이제는 색인 기본 매핑을 업데이트 할 수 없습니다. 가능하다면 알려주십시오. elasticsearch의 기본 인덱스 매핑 업데이트

내가 _default_ 매핑을 지정하는 인덱스를 생성 다음과 같이

답변

0

나는 default mapping을 사용했다. 이 경우 나는 단지 하나의 필드를 가지고,하지만 난 그것을 분석되지 않습니다 있는지 확인하려면 (내가 유형에 걸쳐 페이스 팅을 할 수있는 말) :

curl -XDELETE "http://localhost:9200/test_index" 

curl -XPUT "http://localhost:9200/test_index" -d' 
{ 
    "mappings": { 
     "_default_": { 
     "properties": { 
      "title": { 
       "type": "string", 
       "index": "not_analyzed" 
      } 
     } 
     } 
    } 
}' 

가 그럼 난 문서의 몇 가지를 만들어, 다른 유형의 각 :

curl -XPUT "http://localhost:9200/test_index/doc_type1/1" -d' 
{ "title": "some text" }' 

curl -XPUT "http://localhost:9200/test_index/doc_type2/2" -d' 
{ "title": "some other text" }' 

그래서 각 유형에 대한 매핑이 동적으로 생성되며, "title"의 기본 매핑이 포함됩니다. 우리는 매핑을보고이를 볼 수 있습니다

curl -XGET "http://localhost:9200/test_index/_mapping" 
... 
{ 
    "test_index": { 
     "mappings": { 
     "_default_": { 
      "properties": { 
       "title": { 
        "type": "string", 
        "index": "not_analyzed" 
       } 
      } 
     }, 
     "doc_type2": { 
      "properties": { 
       "title": { 
        "type": "string", 
        "index": "not_analyzed" 
       } 
      } 
     }, 
     "doc_type1": { 
      "properties": { 
       "title": { 
        "type": "string", 
        "index": "not_analyzed" 
       } 
      } 
     } 
     } 
    } 
} 

을 그리고 나는 title 필드에 패싯 경우 내가 기대하는 것을 다시 얻을 것이다 :

: 여기
curl -XPOST "http://localhost:9200/test_index/_search" -d' 
{ 
    "size": 0, 
    "facets": { 
     "title_values": { 
      "terms": { 
      "field": "title", 
      "size": 10 
      } 
     } 
    } 
}' 
... 
{ 
    "took": 1, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 2, 
     "max_score": 0, 
     "hits": [] 
    }, 
    "facets": { 
     "title_values": { 
     "_type": "terms", 
     "missing": 0, 
     "total": 2, 
     "other": 0, 
     "terms": [ 
      { 
       "term": "some text", 
       "count": 1 
      }, 
      { 
       "term": "some other text", 
       "count": 1 
      } 
     ] 
     } 
    } 
} 

내가 사용하는 코드입니다

http://sense.qbox.io/gist/05c503ce9ea841ca4013953b211e00dadf6f1549

이 질문에 대한 답변?

편집 : 여기은 기존 인덱스에 대한 _default_ 매핑을 업데이트 할 수있는 방법은 다음과 같습니다. (나는 그런데,이 대답을 Elasticsearch 버전 1.3.4을 사용)

curl -XPUT "http://localhost:9200/test_index/_default_/_mapping" -d' 
{ 
    "_default_": { 
     "properties": { 
     "title": { 
      "type": "string", 
      "index": "not_analyzed" 
     }, 
     "name": { 
      "type": "string", 
      "index": "not_analyzed" 
     } 
     } 
    } 
}'