2015-01-07 50 views
0

我想为我的索引更新elasticsearch中的默认映射。但是所有的文档都指出,我们必须提供更新映射的类型。问题是我有很多索引类型,并且它们是在出现新类型的文档时动态创建的。所以处理的最佳方式是默认映射类型。因为我不必为每种类型定义映射。但现在我无法更新我的索引默认映射。如果有可能请让我知道?更新elasticsearch中的默认索引映射

回答

0

我用default mapping如下:

我创建索引,指定_default_映射。在这种情况下,我只有一个单一的领域,但我想,以确保它不会分析(这样我就可以跨类型做小面,说):

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" 
     } 
     } 
    } 
}' 

相关问题