#分词验证
POST _analyze
{
"analyzer":"ik_max_word",
"text":"elasticsearch 增删查改"
}
#create a index
PUT blog
#create a mapping
POST blog/_mapping
{
"properties": {
"title": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart"
},
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart"
}
}
}
#index some docs
POST blog/_create/1
{
"title": "elasticsearch",
"content": "Elasticsearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java语言开发的,并作为Apache许可条款下的开放源码发布,是一种流行的企业级搜索引擎。Elasticsearch用于云计算中,能够达..."
}
POST blog/_create/2
{
"title": "C#",
"content": "C#是微软公司发布的一种由C和C++衍生出来的面向对象的编程语言、运行于.NET Framework和.NET Core(完全开源,跨平台)之上的高级程序设计语言。并定于在微软职业开发者论坛(PDC)上登台亮相。C#是微软公司研究员Anders Hejlsberg的最新成果。C#看起来与Java有着..."
}
POST blog/_create/3
{
"title": "JAVA",
"content": "Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行..."
}
#update
POST blog/_update/3
{
"doc": {
"title": "Java"
}
}
#query all
GET blog/_search
#query with highlighting
POST /blog/_search
{
"query": {
"match": {
"content": "思维方式"
}
},
"highlight": {
"pre_tags": [
"<tag1>"
],
"post_tags": [
"</tag1>"
],
"fields": {
"content": {
"type": "plain"
}
}
}
}
#query with highlighting
POST /blog/_search
{
"query": {
"bool": {
"should": [
{
"match_phrase": {
"title": "Java"
}
},
{
"match_phrase": {
"content": "Java"
}
}
]
}
},
"highlight": {
"pre_tags": [
"<tag1>"
],
"post_tags": [
"</tag1>"
],
"fields": {
"content": {
"type": "plain"
},
"title": {
"type": "plain"
}
}
}
}
#delete index
DELETE blog