分享

elasticsearch的template 可不可以向solr的schema.xml那样 维护在一个文件中。

hadroger 发表于 2015-7-16 10:19:34 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 5 20878
elasticsearch的template 可不可以向solr的schema.xml那样  维护在一个文件中。

已有(5)人评论

跳转到指定楼层
bob007 发表于 2015-7-16 19:17:15
没这样搞过,楼主可以试试
回复

使用道具 举报

Alkaloid0515 发表于 2015-7-16 20:18:38
如果完全一样不太可能,每个配置文件对应程序里面一定的设置。
不过大部分应该差不多。
楼主最好查看下他们的配置项。
楼主问的有些笼统,只能说二者有些类似,不可能完全相同
回复

使用道具 举报

hadroger 发表于 2015-7-17 13:41:07
Elasticsearch可以预先定义索引模板,当创建新索引时,可以自动匹配模板。模板包括settings和mappings,以及一个匹配索引的正则。

1. 使用curl方式操作templates

详细查阅:http://www.elasticsearch.org/gui ... ices-templates.html

2. 配置文件方式

在config目录下创建目录templates,所有模板文件都放在config/templates目录下。

例如:test.json,模板匹配所有以“test”开头的索引。
这是网上找的一段   网址  http://blog.csdn.net/july_2/article/details/27551739  
测试没有成功  
按此方式放好了配置文件 并写入了一条数据
curl -XPUT "http://localhost:9288/test/_default_/1" -d'

{

    "title": "The Godfather",

    "site_id": 1

}'

在head中查看 template并不是配置中的template

{
"state": "open",
"settings": {
"index": {
"creation_date": "1437015777034",
"uuid": "LTdea0OlTTCj12Q4iytAyQ",
"number_of_replicas": "1",
"number_of_shards": "5",
"version": {
"created": "1060099"
}
}
},
"mappings": {
"_default_": {
"properties": {
"title": {
"type": "string"
},
"site_id": {
"type": "long"
}
}
}



并不是配置文件中的,不知道问题出在哪里,有配置成功的吗
回复

使用道具 举报

xuanxufeng 发表于 2015-7-17 14:10:04
hadroger 发表于 2015-7-17 13:41
Elasticsearch可以预先定义索引模板,当创建新索引时,可以自动匹配模板。模板包括settings和mappings,以 ...

不知道是楼主漏配了,还是贴出的内容少了
他们之间是有区别的模板名字似乎都木有

[mw_shl_code=html,true]{
"test": {
"template": "test*",
"settings": {
"index.number_of_shards" : 5,
"number_of_replicas" : 1
},
"mappings": {
"_default_" : {
"_source" : {
"enabled" : false
}
},
"news" : {
"_source" : {
"enabled" : true
},
"_all" : {
"enabled" : false
},
"properties" : {
"site_id": {
"type":"integer",
"index":"not_analyzed"
},
"title": {
"type":"string",
"index":"analyzed",
"analyzer":"whitespace"
},
"media_type": {
"type":"short",
"index":"not_analyzed"
}
}
}
}
}
}[/mw_shl_code]
回复

使用道具 举报

hadroger 发表于 2015-7-17 15:49:09
xuanxufeng 发表于 2015-7-17 14:10
不知道是楼主漏配了,还是贴出的内容少了
他们之间是有区别的模板名字似乎都木有

模板名字就是第2行的  test 吧
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条