惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - bluesky4485

在windows环境下基于sublime text3的node.js开发环境搭建 CentOS6.4安装及配置oracle - bluesky4485 Ant学习 - bluesky4485 Springframework3.1源码编译 如何测试java支持的最大内存 win7x64下安装oraclex64版本后,plsql Developer无法登录的问题 VMWare安装redhat9后上网的的问题 Tomcat中部署后JspFactory报异常的解决方案 - bluesky4485 MyEclipse10 中增加svn插件 Oracle连接池信息的修改 OPDS1.1 VMware下Redhat9鼠标选用usb后不能使用的解决办法 m2e插件安装 Java开发Maven环境配置和介绍 javadoc生成出现错误“编码 GBK 的不可映射字符” - bluesky4485 Google常用搜索技巧 - bluesky4485 设置Google不跳转到google.com.hk CodeSmith支持中文配置 jni和C++通信中文乱码的问题 - bluesky4485
Elasticsearch及java客户端jest使用
bluesky4485 · 2014-12-17 · via 博客园 - bluesky4485

本文使用Github中的Elasticsearch-rtf,已经集成了众多的插件,例如必须使用的中文分词等,可以简单的通过配置来启用中文分词。本文主要分为以下几部分:

1、配置和启用中文分词;

2、定义索引的mapping

3、java客户端jest创建和检索索引

4、高亮检索结果

5、集群配置

工具:

由于Elasticsearch完全REST风格,支持json进行交互,简单的curl工具就可以完成很多功能,本文中也有部分操作会直接使用curl。window环境下建议下载一个可执行的curl.exe,找一个目录,然后将目录放到path环境变量中,则curl就可以直接使用了。

配置

定义Mapping

使用json格式的mapping,直接通过image添加到test-index索引中。当然,在此之前得先增加一个叫test-index的索引( curl –XPUT http://localhost:9200/test-index,一个简单的命令就可以完成这个事情了。)

{
    "huangke": {
        "mappings": {
            "index": {
                "properties": {
                    "alttitle": {
                        "index": "analyzed",
                        "type": "string"
                    },
                    "contens": {
                        "properties": {
                            "pageno": {
                                "type": "long"
                            },
                            "pagetext": {
                                "index": "analyzed",
                                "type": "string"
                            }
                        }
                    },
                    "desc": {
                        "index": "analyzed",
                        "type": "string"
                    },
                    "drmi": {
                        "index": "not_analyzed",
                        "type": "string"
                    },
                    "isbn": {
                        "index": "not_analyzed",
                        "type": "string"
                    },
                    "metadatatype": {
                        "index": "not_analyzed",
                        "type": "string"
                    },
                    "metaid": {
                        "index": "not_analyzed",
                        "type": "string"
                    },
                    "publisher": {
                        "index": "analyzed",
                        "type": "string"
                    },
                    "title": {
                        "index": "analyzed",
                        "type": "string"
                    }
                }
            }
        }
    }
}

JEST使用

高亮检索结果

集群配置

cluster.name一样,则表示是一个集群,es默认会根据名字自动发现node节点的机器,并加入到集群中进行管理。通过如下简单的配置,就可以将es的集群搭建好:

master机器:

cluster.name: "logstash_ela"
node.name: "elasticsearch_node0"
node.master: true
node.data: true

node节点机器:node.master配置为false表示此节点就只会用来存储数据,在任何情况下都不会作为master节点(内置选举啥机制等,配置为true的则在某些情况下还是有可能会作为master节点存在的)。

cluster.name: "logstash_ela"
node.name: "elasticsearch_node1"
node.master: false
node.data: true