elasticsearch 部署:
由于本人的硬件设备有限,所以需要在一台服务器上布置三个elasticsearch实例,所以需要修改如下配置:
cluster.name: cluster1
node.name: node1
node.data: true
node.master: true
path.data: d:\\esdata\data\data1
path.logs: d:\\esdata\logs\log1
需要注意的是 不要指定http.port: 9200这个选项,应为单机部署三个实例会导致端口冲突
其他类似修改
elasticsearch 添加ik分词器:
1.首先在https://github.com/medcl/elasticsearch-analysis-ik/releases下载于elasticsearch对应的ik编译好的包
也可以自己重新编译,下载地址https://github.com/medcl/elasticsearch-analysis-ik.git)
2.把压缩包解压在elasticsearch安装目录下的plugin目下的ik文件夹下(如果没有可以手动建)
3.在elasticsearch.yml配置文件中加入一句:index.analysis.analyzer.ik.type: "ik"
elasticsearch支持数据更新:
全部更新:
curl -XPOST "http://127.0.0.1:9200/index/type/id" -d '{}'
局部更新:
如果通过脚本更新需要在elasticsearch.yml中加入一条
script.inline: on
curl -XPOST "http://127.0.0.1:9200/index/type/id/_update?pretty" -d '{"script":"ctx._source.totalnum+=1","upsert":{"totalnum":0}}'
上面的命令会对id对应的文档中的totalnum列加一操作
也可通过doc进行对文档的某一列和几列重新写入
curl -XPOST "http://127.0.0.1:9200/index/type/id/_update?pretty" -d '{"doc":{"totalnum":20}}'
elasticsearch支持数据聚合:
因为我用的是根据关键字词去聚合,但是每一条新闻内容可能包含多个关键字词(用空格分割)
随意在索引模版创建时指定:
"keywords": {
"analyzer": "whitespace",
"type": "string"
}
注意:如果你对进行分词过的列聚合,那么elasticsearch会根据按照分词后的结果聚合,
curl -XPOST "http://127.0.0.1:9200/news/dynamic/_search?pretty" -d '{"aggs":{"group_by_classification":{"terms":{"field":"%s"}}}}'
也可以实现:select field1,sum(field2) from table1 group by field1;
{"aggs":{"group_by_classification":{"terms":{"field":"field1"},"aggs":{"sum":{"field":"field2"}}}}}
由于本人的硬件设备有限,所以需要在一台服务器上布置三个elasticsearch实例,所以需要修改如下配置:
cluster.name: cluster1
node.name: node1
node.data: true
node.master: true
path.data: d:\\esdata\data\data1
path.logs: d:\\esdata\logs\log1
需要注意的是 不要指定http.port: 9200这个选项,应为单机部署三个实例会导致端口冲突
其他类似修改
elasticsearch 添加ik分词器:
1.首先在https://github.com/medcl/elasticsearch-analysis-ik/releases下载于elasticsearch对应的ik编译好的包
也可以自己重新编译,下载地址https://github.com/medcl/elasticsearch-analysis-ik.git)
2.把压缩包解压在elasticsearch安装目录下的plugin目下的ik文件夹下(如果没有可以手动建)
3.在elasticsearch.yml配置文件中加入一句:index.analysis.analyzer.ik.type: "ik"
elasticsearch支持数据更新:
全部更新:
curl -XPOST "http://127.0.0.1:9200/index/type/id" -d '{}'
局部更新:
如果通过脚本更新需要在elasticsearch.yml中加入一条
script.inline: on
curl -XPOST "http://127.0.0.1:9200/index/type/id/_update?pretty" -d '{"script":"ctx._source.totalnum+=1","upsert":{"totalnum":0}}'
上面的命令会对id对应的文档中的totalnum列加一操作
也可通过doc进行对文档的某一列和几列重新写入
curl -XPOST "http://127.0.0.1:9200/index/type/id/_update?pretty" -d '{"doc":{"totalnum":20}}'
elasticsearch支持数据聚合:
因为我用的是根据关键字词去聚合,但是每一条新闻内容可能包含多个关键字词(用空格分割)
随意在索引模版创建时指定:
"keywords": {
"analyzer": "whitespace",
"type": "string"
}
注意:如果你对进行分词过的列聚合,那么elasticsearch会根据按照分词后的结果聚合,
curl -XPOST "http://127.0.0.1:9200/news/dynamic/_search?pretty" -d '{"aggs":{"group_by_classification":{"terms":{"field":"%s"}}}}'
也可以实现:select field1,sum(field2) from table1 group by field1;
{"aggs":{"group_by_classification":{"terms":{"field":"field1"},"aggs":{"sum":{"field":"field2"}}}}}