elasticsearch 搜索提示DSL
1,创建mapping: PUT /news_website
{
"mappings": {
"news" : {
"properties" : {
"title" : {
"type": "text",
"analyzer": "ik_max_word",
"fields": {
"suggest" : {
"type" : "completion",
"analyzer": "ik_max_word"
}
}
},
"content": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
}
2,向索引中写入数据
PUT /news_website/news/1
{
"title": "大话西游电影",
"content": "大话西游的电影时隔20年即将在2017年4月重映"
}
PUT /news_website/news/2
{
"title": "大话西游小说",
"content": "某知名网络小说作家已经完成了大话西游同名小说的出版"
}
PUT /news_website/news/3
{
"title": "大话西游手游",
"content": "网易游戏近日出品了大话西游经典IP的手游,正在火爆内测中"
}
3,suggest 查询
GET /news_website/news/_search
{
"suggest":{
"suggest":{
"prefix":"大话西游",
"completion":{
"field":"title.suggest"
}
}
}
}
GET /forum/article/_search
{
"query": {
"match_phrase": {
"title": {
"query": "java spark",
"slop":
}
}
}
} GET /forum/article/_search
{
"query": {
"match_phrase": {
"content": {
"query": "spark data",
"slop":
}
}
}
} GET /forum/article/_search
{
"query": {
"match_phrase": {
"content": {
"query": "data spark",
"slop":
}
}
}
}
#索引1的分片移动到索引2 POST /_cluster/reroute
{
"commands": [
{
"move": {
"index": "my_index_name",
"shard": ,
"from_node": "node1",
"to_node": "node2"
}
},
{
"allocate": {
"index": "my_index_name",
"shard": ,
"node": "node3"
}
}
]
}
#动态更新最小节点数。 PUT /_cluster/settings
{
"persistent": {
"discovery.zen.minimum_master_nodes":
}
} GET /forum/article/_search
{
"query": {
"match_phrase": {
"content": {
"query": "java best",
"slop":
}
}
}
} GET /books/_search
{
"query": {
"constant_score": {
"filter": {
"range": {
"price": {
"gte": ,
"lt":
}
}
}
}
}
} GET /books/_search
{
"query": {
"constant_score": {
"filter": {
"exists": {
"field": "title"
}
}
}
}
} GET /books/_search
{
"query": {
"constant_score": {
"filter": {
"bool": {
"should": [
{
"range": {
"price": {
"gte": ,
"lte":
}
}
}
]
}
},
"boost": 1.2
}
}
}
POST /books/_search
{
"query": {
"match": {
"title": "Java"
}
},
"size": ,
"from": ,
"_source": [
"title",
"language",
"author"
],
"highlight": {
"fields": {
"title": {}
}
}
} POST ik_index/ik_type/
{
"title":"公路局正在治理解放大道路面积水问题"
} GET ik_index/ik_type/_search
{
"query": {
"match_phrase": {
"title": "道路"
}
}
} GET cars/_search GET ik_index/ik_type/_search
{
"profile": "true",
"query": {
"match_phrase": {
"title.ik_my_max": "道路"
}
}
}
GET /_analyze
{
"analyzer": "ik_max_word",
"text":"公路局正在治理解放大道路面积水问题"
} PUT /my_index
{
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": ,
"max_gram":
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
}
} GET /my_index/_analyze
{
"analyzer": "autocomplete",
"text": "quick brown"
} PUT /my_index/_mapping/my_type
{
"properties": {
"title": {
"type": "string",
"analyzer": "autocomplete",
"search_analyzer": "standard"
}
}
} GET /my_index/my_type/_search
{
"query": {
"match_phrase": {
"title": "hello w"
}
}
} PUT my_index
{
"mappings": {
"my_type": {
"properties": {
"title": {
"type": "keyword"
}
}
}
}
} GET my_index/my_type/_search
{
"query": {
"prefix": {
"title": {
"value": "C3"
}
}
}
} GET /forum/article/_search
{
"query": {
"match_phrase": {
"content": {
"query": "spark data",
"slop":
}
}
}
}GET /forum/article/_search
{
"query": {
"match_phrase": {
"title": {
"query": "java spark",
"slop":
}
}
}
} POST /forum/article//_update
{
"doc": {
"content": "spark is best big data solution based on scala ,an programming language similar to java spark"
}
} GET _analyze
{
"text": "hello world, java spark",
"analyzer": "standard"
} PUT /forum/_mapping/article
{
"properties": {
"new_author_first_name": {
"type": "string",
"copy_to": "new_author_full_name"
},
"new_author_last_name": {
"type": "string",
"copy_to": "new_author_full_name"
},
"new_author_full_name": {
"type": "string"
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"new_author_first_name" : "Peter", "new_author_last_name" : "Smith"} } --> Peter Smith
{ "update": { "_id": ""} }
{ "doc" : {"new_author_first_name" : "Smith", "new_author_last_name" : "Williams"} } --> Smith Williams
{ "update": { "_id": ""} }
{ "doc" : {"new_author_first_name" : "Jack", "new_author_last_name" : "Ma"} } --> Jack Ma
{ "update": { "_id": ""} }
{ "doc" : {"new_author_first_name" : "Robbin", "new_author_last_name" : "Li"} } --> Robbin Li
{ "update": { "_id": ""} }
{ "doc" : {"new_author_first_name" : "Tonny", "new_author_last_name" : "Peter Smith"} } --> Tonny Peter Smith GET /forum/article/_search
{
"query": {
"match": {
"new_author_full_name": "Peter Smith"
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"author_first_name" : "Peter", "author_last_name" : "Smith"} }
{ "update": { "_id": ""} }
{ "doc" : {"author_first_name" : "Smith", "author_last_name" : "Williams"} }
{ "update": { "_id": ""} }
{ "doc" : {"author_first_name" : "Jack", "author_last_name" : "Ma"} }
{ "update": { "_id": ""} }
{ "doc" : {"author_first_name" : "Robbin", "author_last_name" : "Li"} }
{ "update": { "_id": ""} }
{ "doc" : {"author_first_name" : "Tonny", "author_last_name" : "Peter Smith"} } GET /forum/article/_search
{
"query": {
"multi_match": {
"query": "Peter Smith",
"type": "most_fields",
"fields": [ "author_first_name", "author_last_name" ]
}
}
}
POST /forum/_mapping/article
{
"properties": {
"sub_title": {
"type": "string",
"analyzer": "english",
"fields": {
"std": {
"type": "string",
"analyzer": "standard"
}
}
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "learning more courses"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "learned a lot of course"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "we have a lot of fun"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "both of them are good"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "haha, hello world"} } GET /forum/article/_search
{
"query": {
"match": {
"sub_title": "learning courses"
}
}
}
GET /forum/article/_search
{
"query": {
"match": {
"sub_title": "learning courses"
}
}
} GET /forum/article/_search
{
"query": {
"dis_max": {
"queries": [
{ "match": { "title": "java beginner" }},
{ "match": { "body": "java beginner" }}
]
}
}
}
GET /forum/article/_search
{
"query": {
"dis_max": {
"queries": [
{ "match": { "title": "java beginner" }},
{ "match": { "body": "java beginner" }}
],
"tie_breaker": 0.3
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"content" : "i like to write best elasticsearch article"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "i think java is the best programming language"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "i am only an elasticsearch beginner"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "elasticsearch and hadoop are all very good solution, i am a beginner"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "spark is best big data solution based on scala ,an programming language similar to java"} }
GET /forum/article/_search
{
"query": {
"bool": {
"should": [
{ "match": { "title": "java solution" }},
{ "match": { "content": "java solution" }}
]
}
}
}
GET /forum/article/_search
{
"query": {
"dis_max": {
"queries": [
{ "match": { "title": "java solution" }},
{ "match": { "content": "java solution" }}
]
}
}
} GET /forum/article/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "blog"
}
}
],
"should": [
{
"match": {
"title": {
"query": "java"
}
}
},
{
"match": {
"title": {
"query": "hadoop"
}
}
},
{
"match": {
"title": {
"query": "elasticsearch"
}
}
},
{
"match": {
"title": {
"query": "spark",
"boost":
}
}
}
]
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java and elasticsearch blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is elasticsearch blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java, elasticsearch, hadoop blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is spark blog"} } POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java and elasticsearch blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is elasticsearch blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java, elasticsearch, hadoop blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is spark blog"} }
GET /forum/article/_search
{
"query": {
"match": {
"title": {
"query": "java elasticsearch",
"operator": "and"
}
}
}
}
GET /forum/article/_search
{
"query": {
"match": {
"title": {
"query": "java elasticsearch",
"operator": "and"
}
}
}
}
GET /forum/article/_search
{
"query": {
"bool": {
"must": { "match": { "title": "java" }},
"must_not": { "match": { "title": "spark" }},
"should": [
{ "match": { "title": "hadoop" }},
{ "match": { "title": "elasticsearch" }}
]
}
}
}
GET /forum/article/_search
{
"query": {
"bool": {
"should": [
{ "match": { "title": "java" }},
{ "match": { "title": "elasticsearch" }},
{ "match": { "title": "hadoop" }},
{ "match": { "title": "spark" }}
],
"minimum_should_match":
}
}
}
GET /books/_search
{
"size": ,
"aggs": {
"grades_stats": {
"stats": {
"field": "price"
}
}
}
} GET /_search
{
"query": {
"bool": {
"should": [
{ "match": { "address": "mill" } },
{ "match": { "address": "lane" } }
]
}
}
} PUT my_index/my_type/
{
"full_text": "Quick Foxes!",
"exact_value": "Quick Foxes!"
} GET my_index/my_type/_search
{
"query": {
"term": {
"exact_value": "Quick Foxes!"
}
}
} GET my_index/my_type/_search
{
"query": {
"term": {
"full_text": "Quick Foxes!"
}
}
}
GET my_index/my_type/_search
{
"query": {
"term": {
"full_text": "foxes"
}
}
} GET my_index/my_type/_search
{
"query": {
"match": {
"full_text": "Quick Foxes!"
}
}
} POST /termtest/termtype/
{
"content":"Name"
} POST /termtest/termtype/
{
"content":"name city"
} GET /termtest/_search
{
"query":
{
"match_all": {}
}
} POST /termtest/_search
{
"query":{
"term":{
"content":"name"
}
}
} POST /termtest/_search
{
"query":{
"match":{
"content":"Name"
}
}
} PUT my_index/my_type/
{
"zuMaker":
{"type":"keyword","index":"false"} } PUT my_index/my_type/
{
"zuName":
{"type":"text","index":"true","boost":"","analyzer":"ik_max_word","search_analyzer":"ik_max_word"} } PUT my_index/my_type/
{
"zuMaker":
{"type":"keyword","index":"false"} } PUT my_index/my_type/
{
"zuName":
{"type":"text","index":"true","boost":"","analyzer":"ik_max_word","search_analyzer":"ik_max_word"} } GET my_index/my_type/_search { "query": { "term": { "zuName": "墙体钢结构" } } } GET my_index/my_type/_search
{ "query": { "term": { "zuMakert": "张三李四" } } } GET my_index/my_type/_search PUT my_index/my_type/
{
"zuMaker":
{
"type": "keyword",
"index": "false",
"content":"张三李四"
} } PUT my_index/my_type/
{
"zuName": {
"type": "text",
"index": "true",
"boost": "",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"content":"墙体钢结构"
}
}
GET my_index/_search { "query": { "term": { "zuMakert": "张三李四" } } } //设置mapping
POST /productindex/product/_mapping?pretty
{
"product": {
"properties": {
"title": {
"type": "string",
"store": "yes"
},
"description": {
"type": "string",
"index": "not_analyzed"
},
"price": {
"type": "double"
},
"onSale": {
"type": "boolean"
},
"type": {
"type": "integer"
},
"createDate": {
"type": "date"
}
}
}
} //新增mapping
POST /productindex/product/_mapping?pretty
{
"product": {
"properties": {
"amount":{
"type":"integer"
}
}
}
} POST /productindex/product/_mapping?pretty
{
"product": {
"properties": {
"onSale":{
"type":"string"
}
}
}
} //设置mapping之后,插入数据
POST /productindex/product/
{
"title" : "John",
"description" : "Smith",
"price" : ,
"onSale" : "" ,
"type": ,
"createDate" : "2017-08-26"
} //精确查找 GET /test_index2/_search
{
"query": {
"match_phrase": {
"title":"Java程序性能优化"
}
}
} //如果我们希望两个字段进行匹配,其中一个字段有这个文档就满足的话,使用multi_match GET /test_index2/_search
{
"query": {
"multi_match": {
"query" : "Java程序性能优化",
"fields" : ["title", "language"]
}
}
} //boolean 查询 GET /test_index2/_search
{
"query": {
"bool": {
"must": {
"term": {
"title": "java"
}
},
"must_not": {
"term": {
"language": "javascript"
}
}
}
}
} //and or 查询 GET /test_index2/_search
{
"query": {
"match": {
"title": {
"query": "Java Python",
"operator": "or" --and
}
}
}
} //range 过滤 GET /_search
{
"query": {
"range": {
"age": {
"gte": ,
"lt":
}
}
}
} #The filtered query has been deprecated and removed in ES 5.0. You should now use the bool/must/filter query instead. {
"query": {
"bool": {
"must": {
"multi_match": {
"operator": "and",
"fields": [
"author",
"title",
"publisher",
"year"
],
"query": "George Orwell"
}
},
"filter": {
"terms": {
"year": [
, ]
}
}
}
}
}
PUT /artists/
{
"settings": {
"analysis": {
"analyzer": {
"user_name_analyzer": {
"tokenizer": "whitespace",
"filter": "pinyin_first_letter_and_full_pinyin_filter"
}
},
"filter": {
"pinyin_first_letter_and_full_pinyin_filter": {
"type": "pinyin",
"keep_first_letter": true,
"keep_full_pinyin": false,
"keep_none_chinese": true,
"keep_original": false,
"limit_first_letter_length": ,
"lowercase": true,
"trim_whitespace": true,
"keep_none_chinese_in_first_letter": true
}
}
}
}
} GET /artists/_analyze
{
"text": ["刘德华 张学友 郭富城 黎明 王传付 四大天王"],
"analyzer": "user_name_analyzer"
} #查询指定条件的数据
#select * from order o where o.price=
GET /my_store/_search
{
"query": {
"bool": {
"must": {
"match_all": { }
},
"filter": {
"term": {
"price" :
}
}
}
}
} PUT /website
{
"mappings": {
"article": {
"properties": {
"title": {
"type": "text",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
},
"fielddata": true
},
"content": {
"type": "text"
},
"post_date": {
"type": "date"
},
"author_id": {
"type": "long"
}
}
}
}
} PUT /website/article/
{
"title": "first article",
"content": "this is my second article",
"post_date": "2017-01-01",
"author_id":
} {
"took": ,
"timed_out": false,
"_shards": {
"total": ,
"successful": ,
"failed":
},
"hits": {
"total": ,
"max_score": ,
"hits": [
{
"_index": "website",
"_type": "article",
"_id": "",
"_score": ,
"_source": {
"title": "first article",
"content": "this is my first article",
"post_date": "2017-02-01",
"author_id":
}
},
{
"_index": "website",
"_type": "article",
"_id": "",
"_score": ,
"_source": {
"title": "second article",
"content": "this is my second article",
"post_date": "2017-01-01",
"author_id":
}
},
{
"_index": "website",
"_type": "article",
"_id": "",
"_score": ,
"_source": {
"title": "third article",
"content": "this is my third article",
"post_date": "2017-03-01",
"author_id":
}
}
]
}
} GET /website/article/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"title.raw": {
"order": "desc"
}
}
]
} GET /_search
{
"query" : {
"bool" : {
"filter" : {
"term" : {
"author_id" :
}
}
}
}
} 当然,也可以是constant_score GET /_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"author_id" :
}
}
}
}
} 、定制排序规则 GET /company/employee/_search
{
"query": {
"constant_score": {
"filter": {
"range": {
"age": {
"gte":
}
}
}
}
},
"sort": [
{
"join_date": {
"order": "asc"
}
}
]
} GET /website/article/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "elasticsearch"
}
}
],
"should": [
{
"match": {
"content": "elasticsearch"
}
}
],
"must_not": [
{
"match": {
"author_id":
}
}
]
}
}
} GET /test_index/_search
{
"query": {
"bool": {
"must": { "match": { "name": "tom" }},
"should": [
{ "match": { "hired": true }},
{ "bool": {
"must": { "match": { "personality": "good" }},
"must_not": { "match": { "rude": true }}
}}
],
"minimum_should_match":
}
}
} 、match all GET /_search
{
"query": {
"match_all": {}
}
} 、match GET /_search
{
"query": { "match": { "title": "my elasticsearch article" }}
} 、multi match GET /test_index/test_type/_search
{
"query": {
"multi_match": {
"query": "test",
"fields": ["test_field", "test_field1"]
}
}
} 、range query GET /company/employee/_search
{
"query": {
"range": {
"age": {
"gte":
}
}
}
} 、term query GET /test_index/test_type/_search
{
"query": {
"term": {
"test_field": "test hello"
}
}
} 、terms query GET /_search
{
"query": { "terms": { "tag": [ "search", "full_text", "nosql" ] }}
}
PUT /company/employee/
{
"address": {
"country": "china",
"province": "jiangsu",
"city": "nanjing"
},
"name": "tom",
"age": ,
"join_date": "2016-01-01"
} PUT /company/employee/
{
"address": {
"country": "china",
"province": "shanxi",
"city": "xian"
},
"name": "marry",
"age": ,
"join_date": "2015-01-01"
} GET /company/employee/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"join_date": "2016-01-01"
}
}
],
"filter": {
"range": {
"age": {
"gte":
}
}
}
}
}
} 、修改mapping 只能创建index时手动建立mapping,或者新增field mapping,但是不能update field mapping PUT /website
{
"mappings": {
"article": {
"properties": {
"author_id": {
"type": "long"
},
"title": {
"type": "text",
"analyzer": "english"
},
"content": {
"type": "text"
},
"post_date": {
"type": "date"
},
"publisher_id": {
"type": "text",
"index": "not_analyzed"
}
}
}
}
} PUT /website
{
"mappings": {
"article": {
"properties": {
"author_id": {
"type": "text"
}
}
}
}
} {
"error": {
"root_cause": [
{
"type": "index_already_exists_exception",
"reason": "index [website/co1dgJ-uTYGBEEOOL8GsQQ] already exists",
"index_uuid": "co1dgJ-uTYGBEEOOL8GsQQ",
"index": "website"
}
],
"type": "index_already_exists_exception",
"reason": "index [website/co1dgJ-uTYGBEEOOL8GsQQ] already exists",
"index_uuid": "co1dgJ-uTYGBEEOOL8GsQQ",
"index": "website"
},
"status":
} PUT /website/_mapping/article
{
"properties" : {
"new_field" : {
"type" : "string",
"index": "not_analyzed"
}
}
} GET /website/_mapping
、测试mapping GET /website/_analyze
{
"field": "content",
"text": "my-dogs"
} GET website/_analyze
{
"field": "new_field",
"text": "my dogs"
} {
"error": {
"root_cause": [
{
"type": "remote_transport_exception",
"reason": "[4onsTYV][127.0.0.1:9300][indices:admin/analyze[s]]"
}
],
"type": "illegal_argument_exception",
"reason": "Can't process field [new_field], Analysis requests are only supported on tokenized fields"
},
"status":
} PUT /website/article/
{
"post_date": "2017-01-01",
"title": "my first article",
"content": "this is my first article in this website",
"author_id":
} PUT /website/article/
{
"post_date": "2017-01-02",
"title": "my second article",
"content": "this is my second article in this website",
"author_id":
} PUT /website/article/
{
"post_date": "2017-01-03",
"title": "my third article",
"content": "this is my third article in this website",
"author_id":
} 尝试各种搜索 GET /website/_mapping/article {
"website": {
"mappings": {
"article": {
"properties": {
"author_id": {
"type": "long"
},
"content": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above":
}
}
},
"post_date": {
"type": "date"
},
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above":
}
}
}
}
}
}
}
} GET /_search {
"took": ,
"timed_out": false,
"_shards": {
"total": ,
"successful": ,
"failed":
},
"hits": {
"total": ,
"max_score": ,
"hits": [
{
"_index": ".kibana",
"_type": "config",
"_id": "5.2.0",
"_score": ,
"_source": {
"buildNum":
}
}
]
}
}
#bulk语法 POST /_bulk
{ "delete": { "_index": "test_index", "_type": "test_type", "_id": "" }}
{ "create": { "_index": "test_index", "_type": "test_type", "_id": "" }}
{ "test_field": "test12" }
{ "index": { "_index": "test_index", "_type": "test_type", "_id": "" }}
{ "test_field": "replaced test2" }
{ "update": { "_index": "test_index", "_type": "test_type", "_id": "", "_retry_on_conflict" : } }
{ "doc" : {"test_field2" : "bulk test1"} } POST /test_index/_bulk
{ "delete": { "_type": "test_type", "_id": "" }}
{ "create": { "_type": "test_type", "_id": "" }}
{ "test_field": "test12" }
{ "index": { "_type": "test_type" }}
{ "test_field": "auto-generate id test" }
{ "index": { "_type": "test_type", "_id": "" }}
{ "test_field": "replaced test2" }
{ "update": { "_type": "test_type", "_id": "", "_retry_on_conflict" : } }
{ "doc" : {"test_field2" : "bulk test1"} } POST /test_index/test_type/_bulk
{ "delete": { "_id": "" }}
{ "create": { "_id": "" }}
{ "test_field": "test12" }
{ "index": { }}
{ "test_field": "auto-generate id test" }
{ "index": { "_id": "" }}
{ "test_field": "replaced test2" }
{ "update": { "_id": "", "_retry_on_conflict" : } }
{ "doc" : {"test_field2" : "bulk test1"} } GET /_mget
{
"docs" : [
{
"_index" : "test_index",
"_type" : "test_type",
"_id" :
},
{
"_index" : "test_index",
"_type" : "test_type",
"_id" :
}
]
} {
"docs": [
{
"_index": "test_index",
"_type": "test_type",
"_id": "",
"_version": ,
"found": true,
"_source": {
"test_field1": "test field1",
"test_field2": "test field2"
}
},
{
"_index": "test_index",
"_type": "test_type",
"_id": "",
"_version": ,
"found": true,
"_source": {
"test_content": "my test"
}
}
]
} ()如果查询的document是一个index下的不同type种的话 GET /test_index/_mget
{
"docs" : [
{
"_type" : "test_type",
"_id" :
},
{
"_type" : "test_type",
"_id" :
}
]
} ()如果查询的数据都在同一个index下的同一个type下,最简单了 GET /test_index/test_type/_mget
{
"ids": [, ]
} PUT /test_index/test_type/
{
"num": ,
"tags": []
}
POST /test_index/test_type//_update
{
"script" : "ctx._source.num+=1"
} {
"_index": "test_index",
"_type": "test_type",
"_id": "",
"_version": ,
"found": true,
"_source": {
"num": ,
"tags": []
}
} POST /test_index/test_type//_update
{
"script": {
"lang": "groovy",
"file": "test-add-tags",
"params": {
"new_tag": "tag1"
}
}
}
POST /test_index/test_type//_update
{
"doc": {
"num":
}
}
GET /ecommerce/product/_search
{
"aggs": {
"group_by_tags": {
"terms": { "field": "tags" }
}
}
} GET /car/_search GET /car/_search
{
"aggs": {
"group_by_color": {
"terms": { "field": "color" }
}
}
}
PUT /ecommerce/_mapping/product
{
"properties": {
"tags": {
"type": "text",
"fielddata": true
}
}
}
GET /ecommerce/product/_search
{
"size": ,
"aggs": {
"all_tags": {
"terms": { "field": "tags" }
}
}
}
GET /ecommerce/product/_search
{
"size": ,
"query": {
"match": {
"name": "yagao"
}
},
"aggs": {
"all_tags": {
"terms": {
"field": "tags"
}
}
}
}
GET /ecommerce/product/_search
{
"size": ,
"aggs" : {
"group_by_tags" : {
"terms" : { "field" : "tags" },
"aggs" : {
"avg_price" : {
"avg" : { "field" : "price" }
}
}
}
}
} GET /ecommerce/product/_search
{
"size": ,
"aggs" : {
"all_tags" : {
"terms" : { "field" : "tags", "order": { "avg_price": "desc" } },
"aggs" : {
"avg_price" : {
"avg" : { "field" : "price" }
}
}
}
}
} GET /ecommerce/product/_search
{
"size": ,
"aggs": {
"group_by_price": {
"range": {
"field": "price",
"ranges": [
{
"from": ,
"to":
},
{
"from": ,
"to":
},
{
"from": ,
"to":
}
]
},
"aggs": {
"group_by_tags": {
"terms": {
"field": "tags"
},
"aggs": {
"average_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
}
}
GET /ecommerce/product/_search
{
"query": { "match_all": {} }
} GET /ecommerce/product/_search
{
"query" : {
"match" : {
"name" : "yagao"
}
},
"sort": [
{ "price": "desc" }
]
}
GET /ecommerce/product/_search
{
"query": { "match_all": {} },
"from": ,
"size":
}
GET /ecommerce/product/_search
{
"query": { "match_all": {} },
"_source": ["name", "price"]
} GET /ecommerce/product/_search
{
"query" : {
"bool" : {
"must" : {
"match" : {
"name" : "yagao"
}
},
"filter" : {
"range" : {
"price" : { "gt" : }
}
}
}
}
} GET /ecommerce/product/_search
{
"query" : {
"match" : {
"producer" : "yagao producer"
}
}
}
GET /ecommerce/product/_search
{
"query" : {
"match_phrase" : {
"producer" : "yagao producer"
}
}
}
GET /ecommerce/product/_search
{
"query" : {
"match" : {
"producer" : "producer"
}
},
"highlight": {
"fields" : {
"producer" : {}
}
}
}
POST /forum/article/_bulk
{ "index": { "_id": }}
{ "articleID" : "XHDK-A-1293-#fJ3", "userID" : , "hidden": false, "postDate": "2017-01-01" }
{ "index": { "_id": }}
{ "articleID" : "KDKE-B-9947-#kL5", "userID" : , "hidden": false, "postDate": "2017-01-02" }
{ "index": { "_id": }}
{ "articleID" : "JODL-X-1937-#pV7", "userID" : , "hidden": false, "postDate": "2017-01-01" }
{ "index": { "_id": }}
{ "articleID" : "QQPX-R-3956-#aD8", "userID" : , "hidden": true, "postDate": "2017-01-02" } GET /forum/_mapping/article {
"forum": {
"mappings": {
"article": {
"properties": {
"articleID": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above":
}
}
},
"hidden": {
"type": "boolean"
},
"postDate": {
"type": "date"
},
"userID": {
"type": "long"
}
}
}
}
}
}
GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"userID" :
}
}
}
}
} GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"hidden" : false
}
}
}
}
}
GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"postDate" : "2017-01-01"
}
}
}
}
} GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"articleID" : "XHDK-A-1293-#fJ3"
}
}
}
}
}
GET /forum/_analyze
{
"field": "articleID",
"text": "XHDK-A-1293-#fJ3"
} DELETE /forum PUT /forum
{
"mappings": {
"article": {
"properties": {
"articleID": {
"type": "keyword"
}
}
}
}
} POST /forum/article/_bulk
{ "index": { "_id": }}
{ "articleID" : "XHDK-A-1293-#fJ3", "userID" : , "hidden": false, "postDate": "2017-01-01" }
{ "index": { "_id": }}
{ "articleID" : "KDKE-B-9947-#kL5", "userID" : , "hidden": false, "postDate": "2017-01-02" }
{ "index": { "_id": }}
{ "articleID" : "JODL-X-1937-#pV7", "userID" : , "hidden": false, "postDate": "2017-01-01" }
{ "index": { "_id": }}
{ "articleID" : "QQPX-R-3956-#aD8", "userID" : , "hidden": true, "postDate": "2017-01-02" } GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"articleID" : "XHDK-A-1293-#fJ3"
}
}
}
}
}
PUT test_index/test_type/
{
"test_field":"test1"
} GET test_index/test_type/_search PUT test_index/test_type/?version=
{
"test_field":"test3"
} GET website/_search
GET website/_mapping/blogs GET /website/_analyze
{
"field": "content",
"text": "my-dogs"
} GET /_analyze
{
"analyzer": "ik_max_word",
"text": "中华人民共和国"
} GET /_analyze
{
"analyzer": "standard",
"text": "中华人民共和国"
} GET /_analyze
{
"analyzer": "index_ansj",
"text": "中华人民共和国"
} GET /jd_item/_mapping GET /jd_item/jd_item/_search
{
"query": {
"match": {
"title": "飞利浦"
}
}
} GET /jd_item/jd_item/_search
{
"from":,
"size":,
"query": {
"bool": {
"must": [
{
"query_string": {
"default_field": "title",
"query": "飞利浦"
}
},
{
"query_string": {
"default_field": "id",
"query": ""
}
}
]
}
}
} GET /jd_item/jd_item/_search
{
"query": {
"match": {
"title": "飞利"
}
}
}
GET /tvs/sales/_search
{
"size" : ,
"aggs":{
"price":{
"histogram":{
"field": "price",
"interval":
},
"aggs":{
"revenue": {
"sum": {
"field" : "price"
}
}
}
}
}
} GET /tvs/sales/_search
{
"size": ,
"query": {
"term": {
"brand": {
"value": "长虹"
}
}
},
"aggs": {
"recent_150d": {
"filter": {
"range": {
"sold_date": {
"gte": "now-150d"
}
}
},
"aggs": {
"recent_150d_avg_price": {
"avg": {
"field": "price"
}
}
}
},
"recent_140d": {
"filter": {
"range": {
"sold_date": {
"gte": "now-140d"
}
}
},
"aggs": {
"recent_140d_avg_price": {
"avg": {
"field": "price"
}
}
}
},
"recent_130d": {
"filter": {
"range": {
"sold_date": {
"gte": "now-130d"
}
}
},
"aggs": {
"recent_130d_avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
} GET /spnews/news/_search
{
"query": {
"multi_match": {
"query": "足球",
"fields": [
"content^1.0",
"title^1.0"
],
"type": "best_fields",
"operator": "OR",
"slop": ,
"prefix_length": ,
"max_expansions": ,
"lenient": false,
"zero_terms_query": "NONE",
"boost":
}
},
"highlight": {
"pre_tags": [
"<font style='color:red'>"
],
"post_tags": [
"</font>"
],
"fields": {
"title": {},
"content": {}
}
}
}
GET /spnews/news/_search
{
"from": ,
"size": ,
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"match": {
"productCommonName": {
"query": "感冒药",
"type": "boolean",
"operator": "AND",
"boost":
}
}
},
{
"match": {
"productName": {
"query": "感冒药",
"type": "boolean",
"operator": "AND",
"boost":
}
}
},
{
"match": {
"productChnNo": {
"query": "感冒药",
"type": "boolean",
"operator": "AND",
"boost":
}
}
},
{
"match": {
"proCatalogName": {
"query": "感冒药",
"type": "boolean",
"operator": "AND",
"boost":
}
}
},
{
"match": {
"productBrandName": {
"query": "感冒药",
"type": "boolean",
"operator": "AND",
"boost":
}
}
},
{
"match": {
"productBrandName1": {
"query": "感冒药",
"type": "boolean",
"operator": "AND",
"boost":
}
}
},
{
"match": {
"productKeyword": {
"query": "感冒药",
"type": "boolean",
"operator": "AND",
"boost":
}
}
}
]
}
},
{
"bool": {
"should": [
{
"range": {
"saleScore": {
"from": ,
"to": null,
"include_lower": false,
"include_upper": true,
"boost":
}
}
},
{
"range": {
"saleScore": {
"from": null,
"to": ,
"include_lower": true,
"include_upper": false,
"boost":
}
}
}
]
}
}
]
}
},
"post_filter": {
"bool": {
"must_not": {
"term": {
"ecPrice": -
}
}
}
},
"sort": [
{
"stock": {
"order": "desc"
}
},
{
"_score": {
"order": "desc"
}
}
],
"highlight": {
"pre_tags": [
"<em>"
],
"post_tags": [
"</em>"
],
"fields": {
"productName": {
"fragment_size":
}
}
}
}
GET /test_index/test_type/_search
{
"query": {
"match": {
"search_field": "test"
}
},
"aggs": {
"group_by_agg_field": {
"terms": {
"field": "agg_field"
}
}
}
} GET /website/users/_search
{
"query": {
"term": {
"name.keyword": {
"value": "小鱼儿"
}
}
}
} GET /forum/_mapping/article {
"forum": {
"mappings": {
"article": {
"properties": {
"articleID": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above":
}
}
},
"hidden": {
"type": "boolean"
},
"postDate": {
"type": "date"
},
"userID": {
"type": "long"
}
}
}
}
}
} GET /forum/article/_search POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"tag" : ["java", "hadoop"]} }
{ "update": { "_id": ""} }
{ "doc" : {"tag" : ["java"]} }
{ "update": { "_id": ""} }
{ "doc" : {"tag" : ["hadoop"]} }
{ "update": { "_id": ""} }
{ "doc" : {"tag" : ["java", "elasticsearch"]} } GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"terms" : {
"tag" : ["java"]
}
}
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"tag_cnt" : } }
{ "update": { "_id": ""} }
{ "doc" : {"tag_cnt" : } }
{ "update": { "_id": ""} }
{ "doc" : {"tag_cnt" : } }
{ "update": { "_id": ""} }
{ "doc" : {"tag_cnt" : } } POST /forum/article/_bulk
{ "index": { "_id": }}
{ "articleID" : "XHDK-A-1293-#fJ3", "userID" : , "hidden": false, "postDate": "2017-01-01" }
{ "index": { "_id": }}
{ "articleID" : "KDKE-B-9947-#kL5", "userID" : , "hidden": false, "postDate": "2017-01-02" }
{ "index": { "_id": }}
{ "articleID" : "JODL-X-1937-#pV7", "userID" : , "hidden": false, "postDate": "2017-01-01" }
{ "index": { "_id": }}
{ "articleID" : "QQPX-R-3956-#aD8", "userID" : , "hidden": true, "postDate": "2017-01-02" }
GET /forum/article/_search GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"bool": {
"must": [
{
"term": {
"tag_cnt":
}
},
{
"terms": {
"tag": ["java"]
}
}
]
}
}
}
}
} GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"hidden" : false
}
}
}
}
} GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"postDate" : "2017-01-01"
}
}
}
}
} GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"articleID" : "XHDK-A-1293-#fJ3"
}
}
}
}
} GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"articleID.keyword" : "XHDK-A-1293-#fJ3"
}
}
}
}
}
POST /forum/article/_bulk
{ "index": { "_id": }}
{ "articleID" : "XHDK-A-1293-#fJ3", "userID" : , "hidden": false, "postDate": "2017-01-01" }
{ "index": { "_id": }}
{ "articleID" : "KDKE-B-9947-#kL5", "userID" : , "hidden": false, "postDate": "2017-01-02" }
{ "index": { "_id": }}
{ "articleID" : "JODL-X-1937-#pV7", "userID" : , "hidden": false, "postDate": "2017-01-01" }
{ "index": { "_id": }}
{ "articleID" : "QQPX-R-3956-#aD8", "userID" : , "hidden": true, "postDate": "2017-01-02" }
GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"articleID" : "XHDK-A-1293-#fJ3"
}
}
}
}
} GET /forum/article/_search
{
"query": {
"dis_max": {
"queries": [
{ "match": { "title": "java beginner" }},
{ "match": { "content": "java beginner" }}
]
}
}
}
GET /forum/article/_search
{
"query": {
"dis_max": {
"queries": [
{ "match": { "title": "java beginner" }},
{ "match": { "content": "java beginner" }}
],
"tie_breaker": 0.3
}
}
}
GET /my_index/my_type/_search
{
"query": {
"match_phrase_prefix": {
"title": "hello d"
}
}
} GET /my_index/my_type/_search
{
"query": {
"fuzzy": {
"text": {
"value": "surprize",
"fuzziness":
}
}
}
} GET /forum/article/_search
{
"query": {
"multi_match": {
"query": "Peter Smith",
"type": "most_fields",
"fields": [ "author_first_name", "author_last_name" ]
}
}
} GET /forum/article/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"content": "java"
}
},
{
"match": {
"content": "spark"
}
},
{
"bool": {
"should": [
{
"match": {
"content": "solution"
}
},
{
"match": {
"content": "beginner"
}
}
]
}
}
]
}
}
}
GET /forum/article/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"content": "java"
}
}
],
"must_not": [
{
"match": {
"content": "spark"
}
}
]
}
}
} GET /forum/article/_search
{
"query": {
"boosting": {
"positive": {
"match": {
"content": "java"
}
},
"negative": {
"match": {
"content": "spark"
}
},
"negative_boost": 0.2
}
}
} GET /forum/article/_search
{
"query": {
"bool": {
"should": [
{
"constant_score": {
"query": {
"match": {
"title": "java"
}
}
}
},
{
"constant_score": {
"query": {
"match": {
"title": "spark"
}
}
}
}
]
}
}
}
{
"took": ,
"timed_out": false,
"_shards": {
"total": ,
"successful": ,
"failed":
},
"hits": {
"total": ,
"max_score": 0.6931472,
"hits": [
{
"_index": "forum",
"_type": "article",
"_id": "",
"_score": 0.6931472,
"_source": {
"articleID": "KDKE-B-9947-#kL5",
"userID": ,
"hidden": false,
"postDate": "2017-01-02",
"tag": [
"java"
],
"tag_cnt": ,
"view_cnt": ,
"title": "this is java blog",
"content": "i think java is the best programming language",
"sub_title": "learned a lot of course",
"author_first_name": "Smith",
"author_last_name": "Williams"
}
},
{
"_index": "forum",
"_type": "article",
"_id": "",
"_score": 0.5753642,
"_source": {
"articleID": "XHDK-A-1293-#fJ3",
"userID": ,
"hidden": false,
"postDate": "2017-01-01",
"tag": [
"java",
"hadoop"
],
"tag_cnt": ,
"view_cnt": ,
"title": "this is java and elasticsearch blog",
"content": "i like to write best elasticsearch article",
"sub_title": "learning more courses",
"author_first_name": "Peter",
"author_last_name": "Smith"
}
},
{
"_index": "forum",
"_type": "article",
"_id": "",
"_score": 0.51623213,
"_source": {
"articleID": "DHJK-B-1395-#Ky5",
"userID": ,
"hidden": false,
"postDate": "2017-03-01",
"tag": [
"elasticsearch"
],
"tag_cnt": ,
"view_cnt": ,
"title": "this is spark blog",
"content": "spark is best big data solution based on scala ,an programming language similar to java",
"sub_title": "haha, hello world",
"author_first_name": "Tonny",
"author_last_name": "Peter Smith"
}
}
]
}
} PUT /tvs
{
"mappings": {
"sales": {
"properties": {
"price": {
"type": "long"
},
"color": {
"type": "keyword"
},
"brand": {
"type": "keyword"
},
"sold_date": {
"type": "date"
}
}
}
}
} POST /tvs/sales/_bulk
{ "index": {}}
{ "price" : , "color" : "红色", "brand" : "长虹", "sold_date" : "2016-10-28" }
{ "index": {}}
{ "price" : , "color" : "红色", "brand" : "长虹", "sold_date" : "2016-11-05" }
{ "index": {}}
{ "price" : , "color" : "绿色", "brand" : "小米", "sold_date" : "2016-05-18" }
{ "index": {}}
{ "price" : , "color" : "蓝色", "brand" : "TCL", "sold_date" : "2016-07-02" }
{ "index": {}}
{ "price" : , "color" : "绿色", "brand" : "TCL", "sold_date" : "2016-08-19" }
{ "index": {}}
{ "price" : , "color" : "红色", "brand" : "长虹", "sold_date" : "2016-11-05" }
{ "index": {}}
{ "price" : , "color" : "红色", "brand" : "三星", "sold_date" : "2017-01-01" }
{ "index": {}}
{ "price" : , "color" : "蓝色", "brand" : "小米", "sold_date" : "2017-02-12" } GET /tvs/sales/_search
{
"size" : ,
"aggs" : {
"popular_colors" : {
"terms" : {
"field" : "color"
}
}
}
} GET /tvs/sales/_search
{
"size": ,
"query": {
"constant_score": {
"filter": {
"range": {
"price": {
"gte":
}
}
}
}
},
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
}
}
}
GET /tvs/sales/_search
{
"size" : ,
"aggs" : {
"months" : {
"date_histogram": {
"field": "sold_date",
"interval": "month"
},
"aggs": {
"distinct_colors" : {
"cardinality" : {
"field" : "brand"
}
}
}
}
}
} PUT /blog_website
{
"mappings": {
"blogs": {
"properties": {
"title": {
"type": "text",
"analyzer": "ik_max_word"
},
"content": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
} PUT /blog_website/blogs/
{
"title": "我的第一篇博客",
"content": "大家好,这是我写的第一篇博客,特别喜欢这个博客网站!!!"
} GET /blog_website/blogs/_search
{
"query": {
"match": {
"title": "博客"
}
},
"highlight": {
"fields": {
"title": {}
}
}
} GET /blog_website/blogs/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"title": "博客"
}
},
{
"match": {
"content": "博客"
}
}
]
}
},
"highlight": {
"fields": {
"title": {},
"content": {}
}
}
} PUT /news_website
{
"mappings": {
"news" : {
"properties" : {
"title" : {
"type": "text",
"analyzer": "ik_max_word",
"fields": {
"suggest" : {
"type" : "completion",
"analyzer": "ik_max_word"
}
}
},
"content": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
} PUT /news_website_pinyin
{
"mappings": {
"news_pinyin" : {
"properties" : {
"title" : {
"type": "text",
"analyzer": "pinyin_analyzer",
"fields": {
"suggest" : {
"type" : "completion",
"analyzer": "pinyin_analyzer"
}
}
},
"content": {
"type": "text",
"analyzer": "pinyin_analyzer"
}
}
}
}
} PUT /medcl1/
{
"index" : {
"analysis" : {
"analyzer" : {
"ngram_pinyin_analyzer" : {
"tokenizer" : "keyword",
"filter" : ["full_pinyin_with_space","word_delimiter","shingle","remove_whitespace"]
}, "my_pinyin_analyzer" : {
"tokenizer" : "keyword",
"filter" : ["full_pinyin_no_space"]
}
},
"filter" :{
"full_pinyin_no_space" : {
"type" : "pinyin",
"first_letter" : "none",
"padding_char" : ""
},"full_pinyin_with_space" : {
"type" : "pinyin",
"first_letter" : "none",
"padding_char" : " "
},
"my_edge_ngram_tokenizer" : {
"type" : "edgeNGram",
"min_gram" : "",
"max_gram" : "",
"token_chars": [ "letter", "digit" ]
},
"remove_whitespace": {
"type": "pattern_replace",
"pattern": "\\s+",
"replacement":""
}
}
}
}
} POST medcl1/type/_mapping
{
"properties": {
"name1":{
"type": "multi_field",
"fields": {
"pinyin":{
"type": "string",
"analyzer": "ngram_pinyin_analyzer"
}, "full_pinyin":{
"type": "string",
"analyzer": "my_pinyin_analyzer"
},
"first_letter":{
"type": "string",
"analyzer": "pinyin_first_letter"
},
"name1":{
"type": "string",
"analyzer": "ik_max_word"
}
}
}
}
} GET medcl1/_mapping POST medcl1/type3/
{
"name1":"刘德华"
}
POST medcl1/type3/
{
"name1":"刘斌"
}
POST medcl1/type3/
{
"name1":"张三"
}
POST medcl1/type3/
{
"name1":"李四"
}
POST medcl1/type3/
{
"name1":"刘德志"
} POST medcl1/_search?size=
{
"query": {
"query_string": {
"fields": ["name1","name1.full_pinyin","name1.pinyin","name1.first_letter"],
"query": "刘德华",
"default_operator": "AND"
}
}
} PUT /search_text
{
"settings": {
"refresh_interval": "5s",
"number_of_shards": ,
"number_of_replicas": ,
"analysis": {
"filter": {
"edge_ngram_filter": {
"type": "edge_ngram",
"min_gram": ,
"max_gram":
},
"pinyin_full_filter": {
"type": "pinyin",
"keep_first_letter": false,
"keep_separate_first_letter": false,
"keep_full_pinyin": true,
"keep_original": false,
"limit_first_letter_length": ,
"lowercase": true
},
"pinyin_simple_filter": {
"type": "pinyin",
"keep_first_letter": true,
"keep_separate_first_letter": false,
"keep_full_pinyin": false,
"keep_original": false,
"limit_first_letter_length": ,
"lowercase": true
}
},
"analyzer": {
"pinyiSimpleIndexAnalyzer": {
"type": "custom",
"tokenizer": "keyword",
"filter": [
"pinyin_simple_filter",
"edge_ngram_filter",
"lowercase"
]
},
"pinyiFullIndexAnalyzer": {
"type": "custom",
"tokenizer": "keyword",
"filter": [
"pinyin_full_filter",
"lowercase"
]
}
}
}
}
} PUT /search_text/_mapping/list
{
"properties": {
"name": {
"type": "keyword",
"fields": {
"fpy": {
"type": "text",
"index": true,
"analyzer": "pinyiFullIndexAnalyzer"
},
"spy": {
"type": "text",
"index": true,
"analyzer": "pinyiSimpleIndexAnalyzer"
}
}
}
}
} PUT /search_text/list/
{
"name":"刘德华"
} PUT /search_text/list/
{
"name":"天命"
}
PUT /search_text/list/
{
"name":"你好明天"
}
POST /search_text/list/_search
{
"query":{
"match":{
"name.fpy":{
"query":"liudehua",
"operator": "and"
}
}
}
} GET /news_website/news/_mapping PUT /news_website/news/
{
"title": "大话西游电影dhxy",
"content": "大话西游的电影时隔20年即将在2017年4月重映"
}
PUT /news_website/news/
{
"title": "大话西游小说dhxy",
"content": "某知名网络小说作家已经完成了大话西游同名小说的出版"
}
PUT /news_website/news/
{
"title": "大话西游手游dhxy",
"content": "网易游戏近日出品了大话西游经典IP的手游,正在火爆内测中"
} GET /news_website/news/_search
{
"suggest": {
"my-suggest" : {
"prefix" : "dhxy",
"completion" : {
"field" : "title.suggest"
}
}
}
}
GET /news_website/news/_search
{
"query": {
"match": {
"content": "大话西游电影"
}
}
} PUT /my_index
{
"mappings": {
"my_type": {
"properties": {
"text": {
"type": "text",
"term_vector": "with_positions_offsets_payloads",
"store" : true,
"analyzer" : "fulltext_analyzer"
},
"fullname": {
"type": "text",
"analyzer" : "fulltext_analyzer"
}
}
}
},
"settings" : {
"index" : {
"number_of_shards" : ,
"number_of_replicas" :
},
"analysis": {
"analyzer": {
"fulltext_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"type_as_payload"
]
}
}
}
}
} PUT /my_index/my_type/
{
"fullname" : "Leo Li",
"text" : "hello test test test "
} PUT /my_index/my_type/
{
"fullname" : "Leo Li",
"text" : "other hello test ..."
} GET /my_index/my_type//_termvectors
{
"fields" : ["text"],
"offsets" : true,
"payloads" : true,
"positions" : true,
"term_statistics" : true,
"field_statistics" : true
} {
"_index": "my_index",
"_type": "my_type",
"_id": "",
"_version": ,
"found": true,
"took": ,
"term_vectors": {
"text": {
"field_statistics": {
"sum_doc_freq": ,
"doc_count": ,
"sum_ttf":
},
"terms": {
"hello": {
"doc_freq": ,
"ttf": ,
"term_freq": ,
"tokens": [
{
"position": ,
"start_offset": ,
"end_offset": ,
"payload": "d29yZA=="
}
]
},
"test": {
"doc_freq": ,
"ttf": ,
"term_freq": ,
"tokens": [
{
"position": ,
"start_offset": ,
"end_offset": ,
"payload": "d29yZA=="
},
{
"position": ,
"start_offset": ,
"end_offset": ,
"payload": "d29yZA=="
},
{
"position": ,
"start_offset": ,
"end_offset": ,
"payload": "d29yZA=="
}
]
}
}
}
}
}
GET /my_index/my_type//_termvectors
{
"fields" : ["fullname"],
"offsets" : true,
"positions" : true,
"term_statistics" : true,
"field_statistics" : true
}GET /my_index/my_type/_termvectors
{
"doc" : {
"fullname" : "Leo Li",
"text" : "hello test test test"
},
"fields" : ["text"],
"offsets" : true,
"payloads" : true,
"positions" : true,
"term_statistics" : true,
"field_statistics" : true
}
GET /company/rd_center/_search
{
"size": ,
"aggs": {
"group_by_country": {
"terms": {
"field": "country.keyword"
},
"aggs": {
"group_by_child_employee": {
"children": {
"type": "employee"
},
"aggs": {
"group_by_hobby": {
"terms": {
"field": "hobby.keyword"
}
}
}
}
}
}
}
} GET /movies/_search
{
"from": ,
"size": ,
"query": {
"match_all": {}
}
} GET /forum/_search GET /forum/_mapping/article GET /forum/_search
{
"query": {
"constant_score": {
"filter": {
"term": {
"userID": ""
}
}
}
}
} GET /forum/_search
{
"query": {
"bool": {
"must_not": [
{
"term": {
"postDate": {
"value": "2017-01-02"
}
}
}
],
"should": [
{
"term": {
"postDate": "2017-01-01"
}
},
{
"term": {
"articleID": "XHDK-A-1293-#fJ3"
}
}
]
}
}
} GET /forum/_search
{
"query": {
"bool": {
"should": [
{
"term": {
"postDate":"2017-01-01" }
},{
"term": {
"articleID":"XHDK-A-1293-#fJ3"
}
}
]
}
}
}
GET /forum/_search
{
"query": {
"bool": {
"should": [
{
"term": {
"postDate":"2017-01-01"
}
},{
"term": {
"articleID":"XHDK-A-1293-#fJ3"
}
}
],
"must_not": [
{
"term": {
"postDate":"2017-01-02"
}
}
]
}
}
}
GET /forum/_search
{
"query": {
"constant_score": {
"filter": {
"bool": {
"should": [
{
"term": {
"articleID": "XHDK-A-1293-#fJ3"
}
}
],
"bool": {
"must": [
{
"term": {
"articleID": "JODL-X-1937-#pV7"
}
}
]
}
}
}
}
}
} GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"bool": {
"should": [
{
"term": {
"articleID": "XHDK-A-1293-#fJ3"
}
},
{
"bool": {
"must": [
{
"term": {
"articleID": "JODL-X-1937-#pV7"
}
},
{
"term": {
"postDate": "2017-01-01"
}
}
]
}
}
]
}
}
}
}
} #搜索帖子ID为XHDK-A--#fJ3,或者是帖子ID为JODL-X--#pV7而且发帖日期为2017--01的帖子 GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"bool": {
"should": [
{
"term": {
"articleID": "XHDK-A-1293-#fJ3"
}
},
{
"bool": {
"must": [
{
"term": {
"postDate": "2017-01-01"
}
},
{
"term":{
"articleID": "JODL-X-1937-#pV7"
}
}
]
}
}
]
}
}
}
}
}
GET /forum/article/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"postDate": "2017-01-01"
}
}
],
"should": [
{
"term": {
"articleID": "XHDK-A-1293-#fJ3"
}
}, {
"term": {"articleID": "JODL-X-1937-#pV7"
}
}
]
}
}
}
GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"terms": {
"articleID": [
"KDKE-B-9947-#kL5",
"QQPX-R-3956-#aD8"
]
}
}
}
}
} GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"terms": {
"articleID": [
"KDKE-B-9947-#kL5",
"QQPX-R-3956-#aD8"
]
}
}
}
}
}
GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"terms": {
"tag" : ["java"]
}
}
}
}
} GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"bool": {
"must": [
{
"term": {
"tag_cnt":
}
},
{
"terms": {
"tag": ["java"]
}
}
]
}
}
}
}
} GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"bool": {
"must":[
{
"term":{
"tag_cnt":
}
},{
"terms":{
"tag": ["java"]
}
}
]
}
}
}
}
} GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"range": {
"view_cnt": {
"gte": ,
"lte":
}
}
} }
}
}
#最近一个月的帖子
GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"range": {
"postDate": {
"gt": "2017-03-10||-30d"
}
}
}
}
}
} GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"range": {
"postDate": {
"gte": "now-30d"
}
}
}
}
}
}
GET /forum/article/_mapping
GET /forum/article/_search
{
"query": {
"match": {
"title": "java elasticsearch"
}
}
} GET /forum/article/_search
{
"query": {
"match": {
"title": {
"query": "java elasticsearch",
"operator": "and"
}
}
}
}
GET /forum/article/_search
{
"query": {
"match": {
"title":{
"query": "java elasticsearch spark hadoop",
"minimum_should_match": "75%"
}
}
}
}
GET /forum/article/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "java"
}
}
],"must_not": [
{
"match": {
"title": "spark"
}
}
],
"should": [
{
"match": {
"title": "hadoop"
}
},{
"match": {
"title": "elasticsearch"
}
}
]
}
}
}
GET /forum/article/_search
{
"query": {
"bool": {
"must": {
"match": {
"title": "java"
}
},
"must_not": {
"match": {
"title": "spark"
}
},
"should": [
{
"match": {
"title": "hadoop"
}
},
{
"match": {
"title": "elasticsearch"
}
}
]
}
}
}
GET /forum/article/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"title": "java"
}
},
{
"match": {
"title": "elasticsearch"
}
},
{
"match": {
"title": "spark"
}
},
{
"match": {
"title": "hadoop"
}
} ],
"minimum_should_match":
}
}
} GET /forum/article/_search
{
"query": {
"match": {
"title": {
"query": "",
"operator": "and"
}
}
}
} GET /forum/article/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "blog"
}
}
],
"should": [
{
"match": {
"title": {
"query": "java"
}
}
},
{
"match": {
"title": {
"query": "hadoop"
}
}
},
{
"match": {
"title": {
"query": "elasticsearch"
}
}
},
{
"match": {
"title": {
"query": "spark",
"boost":
}
}
}
]
}
}
} GET /forum/article/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "blog"
}
}
],
"should": [
{
"match": {
"title": {
"query": "java"
}
}
},
{
"match": {
"title": {
"query": "hadoop"
}
}
},
{
"match": {
"title": {
"query": "elasticsearch"
}
}
},
{
"match": {
"title": {
"query": "spark",
"boost":
}
}
}
]
}
}
} GET /forum/article/_search
{
"query": {
"bool": {
"should": [
{ "match": { "title": "java solution" }},
{ "match": { "content": "java solution" }}
]
}
}
} GET /forum/article/_search
POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"content" : "i like to write best elasticsearch article"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "i think java is the best programming language"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "i am only an elasticsearch beginner"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "elasticsearch and hadoop are all very good solution, i am a beginner"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "spark is best big data solution based on scala ,an programming language similar to java"} }
GET /forum/article/_search
{
"query":{
"bool": {
"should": [
{
"match": {
"content": "java solution"
}
},{
"match": {
"title": "java solution"
}
}
]
}
}
}
GET /forum/article/_search GET /forum/article/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"content": "java solution"
}
},
{
"match": {
"title": "java solution"
}
}
]
}
}
} GET /forum/article/_search
{
"query": {
"dis_max": {
"queries": [
{
"match": {
"title": "java solution"
}
},{
"match": {
"content": "java solution"
}
}
]
}
}
} GET /forum/article/_search
{
"query": {
"dis_max": {
"queries": [
{ "match": { "title": "java beginner" }},
{ "match": { "content": "java beginner" }}
],
"tie_breaker": 0.3 }
}
} GET /forum/article/_search
{
"query": {
"multi_match": {
"query": "java solution",
"fields": [ "title^2", "content" ],
"tie_breaker": 0.3,
"minimum_should_match": "50%" }
}
} GET /forum/article/_search
{
"query": {
"match": {
"sub_title": "learning courses"
}
}
} GET /forum/article/_search
{
"query": {
"match": {
"sub_title": "Tlearning courses"
}
}
}
GET /forum/article/_mapping POST /forum/_mapping/article
{
"properties": {
"sub_title": {
"type": "string",
"analyzer": "english",
"fields": {
"std": {
"type": "string",
"analyzer": "standard"
}
}
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "learning more courses"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "learned a lot of course"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "we have a lot of fun"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "both of them are good"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "haha, hello world"} } GET /forum/article/_search GET /forum/article/_search
{
"query": {
"match": {
"sub_title": "learning courses"
}
}
} POST /forum/_mapping/article
{
"properties": {
"sub_title": {
"type": "string",
"analyzer": "english",
"fields": {
"std": {
"type": "string",
"analyzer": "standard"
}
}
}
}
}
post /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "learning more courses"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "learned a lot of course"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "we have a lot of fun"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "both of them are good"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "haha, hello world"} } GET /forum/article/_search
{
"query": {
"match": {
"sub_title": "learning courses"
}
}
}
POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java and elasticsearch blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is elasticsearch blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java, elasticsearch, hadoop blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is spark blog"} } get /forum/article/_search POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java and elasticsearch blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is elasticsearch blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java, elasticsearch, hadoop blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is spark blog"} } POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"tag" : ["java", "hadoop"]} }
{ "update": { "_id": ""} }
{ "doc" : {"tag" : ["java"]} }
{ "update": { "_id": ""} }
{ "doc" : {"tag" : ["hadoop"]} }
{ "update": { "_id": ""} }
{ "doc" : {"tag" : ["java", "elasticsearch"]} } POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java and elasticsearch blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is elasticsearch blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java, elasticsearch, hadoop blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is spark blog"} } POST /forum/_mapping/article
{
"properties": {
"sub_title": {
"type": "string",
"analyzer": "english",
"fields": {
"std": {
"type": "string",
"analyzer": "standard"
}
}
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "learning more courses"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "learned a lot of course"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "we have a lot of fun"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "both of them are good"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "haha, hello world"} } GET /forum/article/_search
{
"query": {
"match": {
"sub_title": "learning courses"
}
}
}
GET /forum/article/_search
{
"query": {
"match": {
"sub_title": "learning courses"
}
}
} GET /forum/article/_search
{
"query": {
"multi_match": {
"query": "learning courses",
"type": "most_fields",
"fields": [ "sub_title", "sub_title.std" ]
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"author_first_name" : "Peter", "author_last_name" : "Smith"} }
{ "update": { "_id": ""} }
{ "doc" : {"author_first_name" : "Smith", "author_last_name" : "Williams"} }
{ "update": { "_id": ""} }
{ "doc" : {"author_first_name" : "Jack", "author_last_name" : "Ma"} }
{ "update": { "_id": ""} }
{ "doc" : {"author_first_name" : "Robbin", "author_last_name" : "Li"} }
{ "update": { "_id": ""} }
{ "doc" : {"author_first_name" : "Tonny", "author_last_name" : "Peter Smith"} } GET /forum/article/_search
{
"query": {
"multi_match": {
"query": "Peter Smith",
"type": "most_fields",
"fields": ["author_first_name","author_last_name"]
}
}
} PUT /forum/_mapping/article
{
"properties": {
"new_author_first_name": {
"type": "string",
"copy_to": "new_author_full_name"
},
"new_author_last_name": {
"type": "string",
"copy_to": "new_author_full_name"
},
"new_author_full_name": {
"type": "string"
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"new_author_first_name" : "Peter", "new_author_last_name" : "Smith"} }
{ "update": { "_id": ""} }
{ "doc" : {"new_author_first_name" : "Smith", "new_author_last_name" : "Williams"} }
{ "update": { "_id": ""} }
{ "doc" : {"new_author_first_name" : "Jack", "new_author_last_name" : "Ma"} }
{ "update": { "_id": ""} }
{ "doc" : {"new_author_first_name" : "Robbin", "new_author_last_name" : "Li"} }
{ "update": { "_id": ""} }
{ "doc" : {"new_author_first_name" : "Tonny", "new_author_last_name" : "Peter Smith"} } GET /forum/article/_search
{
"query": {
"match": {
"new_author_full_name": "Peter Smith"
}
}
}
GET /forum/article/_search
{
"from": ,
"size": ,
"query": {
"match": {
"content": "java "
}
}
}
GET /forum/article/_search
{
"query": {
"match_phrase": {
"content": "java spark"
}
}
} POST /forum/article//_update
{
"doc": {
"content": "spark is best big data solution based on scala ,an programming language similar to java spark"
}
} GET /_analyze
{
"text": "hello world, java spark",
"analyzer": "standard"
} GET /forum/article/_search
{
"query": {
"match_phrase": {
"content": "java spark"
}
}
} GET /forum/article/_search
{
"query": {
"match_all": {}
}
} GET /forum/article/_search
{
"query": {
"match_phrase": {
"content": {
"query": "java best",
"slop":
}
}
}
}
GET /forum/article/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"content": "java spark"
}
}
],
"should": [
{
"match_phrase": {
"content":{
"query": "java spark",
"slop":
}
}
}
]
}
}
}
GET /forum/article/_search
{
"query": {
"match": {
"content": "java spark"
}
},
"rescore": {
"window_size": ,
"query": {
"rescore_query": {
"match_phrase": {
"content": {
"query": "java spark",
"slop":
}
}
}
}
}
} GET /forum/article/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"title": {
"query": "java spark",
"boost":
}
}
},
{
"match":{ "content": "java spark" }
}
]
}
}
} GET /forum/article/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"title": {
"query": "java spark",
"boost":
}
}
},
{
"match": {
"content": "java spark"
}
}
]
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"content" : "i like to write best elasticsearch article"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "i think java is the best programming language"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "i am only an elasticsearch beginner"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "elasticsearch and hadoop are all very good solution, i am a beginner"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "spark is best big data solution based on scala ,an programming language similar to java"} } POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"follower_num" : } }
{ "update": { "_id": ""} }
{ "doc" : {"follower_num" : } }
{ "update": { "_id": ""} }
{ "doc" : {"follower_num" : } }
{ "update": { "_id": ""} }
{ "doc" : {"follower_num" : } }
{ "update": { "_id": ""} }
{ "doc" : {"follower_num" : } } GET /forum/article/_search
{
"query": {
"function_score": {
"query": {
"multi_match": {
"query": "java spark",
"fields": ["tile", "content"]
}
},
"field_value_factor": {
"field": "follower_num",
"modifier": "log1p",
"factor": 0.5
},
"boost_mode": "sum",
"max_boost":
}
}
}
POST /my_index/my_type/_bulk
{ "index": { "_id": }}
{ "text": "Surprise me!"}
{ "index": { "_id": }}
{ "text": "That was surprising."}
{ "index": { "_id": }}
{ "text": "I wasn't surprised."} GET /my_index/my_type/_search
{
"query": {
"fuzzy": {
"text":{
"value": "surprize",
"fuzziness":
}
}
}
} GET /my_index/my_type/_search
{
"query": {
"match": {
"text": {
"query": "SURPIZE ME",
"fuzziness": "AUTO"
}
}
}
}
GET /my_index/my_type/_search
{
"query": {
"match": {
"text":{
"query": "SURPIZE ME"
, "fuzziness": "AUTO",
"operator": "and"
}
}
}
}
GET /my_index/_analyze
{
"text": "男子偷上万元发红包求交女友 被抓获时仍然单身",
"analyzer": "ik_max_word"
} GET /my_index/my_type/_search
{
"query": {
"match": {
"text": "16岁少女结婚好还是单身好?"
}
}
} PUT /my_index
{
"mappings": {
"my_type": {
"properties": {
"text": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
} POST /my_index/my_type/_bulk
{ "index": { "_id": ""} }
{ "text": "男子偷上万元发红包求交女友 被抓获时仍然单身" }
{ "index": { "_id": ""} }
{ "text": "16岁少女为结婚“变”22岁 7年后想离婚被法院拒绝" }
{ "index": { "_id": ""} }
{ "text": "深圳女孩骑车逆行撞奔驰 遭索赔被吓哭(图)" }
{ "index": { "_id": ""} }
{ "text": "女人对护肤品比对男票好?网友神怼" }
{ "index": { "_id": ""} }
{ "text": "为什么国内的街道招牌用的都是红黄配?" } DELETE my_index PUT /my_index
{
"mappings": {
"my_type": {
"properties": {
"text": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
}
POST /my_index/my_type/_bulk
{ "index": { "_id": ""} }
{ "text": "男子偷上万元发红包求交女友 被抓获时仍然单身" }
{ "index": { "_id": ""} }
{ "text": "16岁少女为结婚“变”22岁 7年后想离婚被法院拒绝" }
{ "index": { "_id": ""} }
{ "text": "深圳女孩骑车逆行撞奔驰 遭索赔被吓哭(图)" }
{ "index": { "_id": ""} }
{ "text": "女人对护肤品比对男票好?网友神怼" }
{ "index": { "_id": ""} }
{ "text": "为什么国内的街道招牌用的都是红黄配?" } GET /my_index/my_type/_search
{
"query": {
"match": {
"text": "16岁少女结婚好还是单身好?"
}
}
}
GET /my_index/_analyze
{
"text":"16岁少女结婚好还是单身好",
"analyzer": "ik_max_word"
} PUT /tvs
{
"mappings": {
"sales": {
"properties": {
"price": {
"type": "long"
},
"color": {
"type": "keyword"
},
"brand": {
"type": "keyword"
},
"sold_date": {
"type": "date"
}
}
}
}
}
GET /tvs/sales/_search
{
"size": ,
"aggs": {
"popular_colors": {
"terms": {
"field": "color"
}
}
}
}
GET /tvs/sales/_search
{
"size" : ,
"aggs": {
"colors": {
"terms": {
"field": "color"
},
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
GET /tvs/sales/_search
{
"size": ,
"aggs": {
"colors": {
"terms": {
"field": "color"
},
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
} GET /tvs/sales/_search
{
"size": ,
"aggs": {
"group_by_color": {
"terms": {
"field": "color"
},
"aggs": {
"color_avg_price": {
"avg": {
"field": "price"
}
},
"group_by_brand": {
"terms": {
"field": "brand"
},
"aggs": {
"brand_avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
}
}
GET /tvs/sales/_search
{
"size": ,
"aggs": {
"group_by_color": {
"terms": {
"field": "color"
},
"aggs": {
"color_avg_price": {
"avg": {
"field": "price"
}
},
"group_by_brand": {
"terms": {
"field": "brand"
},
"aggs": {
"brand_avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
}
}
GET /tvs/sales/_search
{
"size": ,
"aggs": {
"colors": {
"terms": {
"field": "color"
},
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
},
"min_price": {
"min": {
"field": "price"
}
},
"max_price": {
"max": {
"field": "price"
}
},
"sum_price": {
"sum": {
"field": "price"
}
}
}
}
}
}
GET /tvs/sales/_search
{
"size": ,
"aggs": {
"colors": {
"terms": {
"field": "color" },
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
},
"max_price":{
"max": {
"field": "price"
}
},
"min_price":{
"min": {
"field": "price"
}
},
"sum_price":{
"sum": {
"field": "price"
}
}
}
}
}
} GET /tvs/sales/_search
{
"size" : ,
"aggs":{
"price":{
"histogram":{
"field": "price",
"interval":
},
"aggs":{
"revenue": {
"sum": {
"field" : "price"
}
}
}
}
}
}
GET /tvs/sales/_search
{
"size": ,
"aggs": {
"price": {
"histogram": {
"field": "price",
"interval":
},
"aggs": {
"revenue":{
"sum": {
"field": "price"
}
}
}
}
}
}
GET /tvs/sales/_search
{
"size": ,
"aggs": {
"sales": {
"date_histogram": {
"field": "date",
"interval": "month",
"format": "yyyy-MM-dd",
"min_doc_count": ,
"extended_bounds":{
"min" : "2016-01-01",
"max" : "2017-12-31"
}
}
}
}
} GET /tvs/sales/_search
{
"size": ,
"aggs": {
"group_by_sold_date": {
"date_histogram": {
"field": "sold_date",
"interval": "quarter",
"format": "yyyy-MM-dd",
"min_doc_count": ,
"extended_bounds": {
"min": "2016-01-01",
"max": "2017-12-31"
}
},
"aggs": {
"group_by_brand": {
"terms": {
"field": "brand"
},
"aggs": {
"sum_price": {
"sum": {
"field": "price"
}
}
}
},
"total_sum_price": {
"sum": {
"field": "price"
}
}
}
}
}
} GET /tvs/sales/_search
{
"size":,
"aggs": {
"group_by_sold_date": {
"date_histogram": {
"field": "date",
"interval": "quarter",
"min_doc_count": ,
"extended_bounds":{
"min": "2016-01-01",
"max": "2017-12-31"
}
},
"aggs": {
"group_by_brand": {
"terms": {
"field": "brand"
},
"aggs": {
"sum_price": {
"sum": {
"field": "price"
}
}
}
},
"total_price":{
"sum": {
"field": "price"
}
}
}
}
}
}
GET /tvs/sales/_search
{
"size": ,
"query": {
"constant_score": {
"filter": {
"range": {
"price": {
"gte":
}
}
}
}
},
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
}
}
} GET /tvs/sales/_search
{
"size" : ,
"aggs" : {
"months" : {
"date_histogram": {
"field": "sold_date",
"interval": "month"
},
"aggs": {
"distinct_colors" : {
"cardinality" : {
"field" : "brand"
}
}
}
}
}
}
#qu'chong去重
GET /tvs/sales/_search
{
"aggs": {
"months": {
"date_histogram": {
"field": "sold_date",
"interval": "month" },
"aggs": {
"distinct_colors": {
"cardinality": {
"field": "brand",
"precision_threshold":
}
}
}
}
}
} POST /website/logs/_bulk
{ "index": {}}
{ "latency" : , "province" : "江苏", "timestamp" : "2016-10-28" }
{ "index": {}}
{ "latency" : , "province" : "江苏", "timestamp" : "2016-10-29" }
{ "index": {}}
{ "latency" : , "province" : "江苏", "timestamp" : "2016-10-29" }
{ "index": {}}
{ "latency" : , "province" : "江苏", "timestamp" : "2016-10-28" }
{ "index": {}}
{ "latency" : , "province" : "江苏", "timestamp" : "2016-10-28" }
{ "index": {}}
{ "latency" : , "province" : "江苏", "timestamp" : "2016-10-29" }
{ "index": {}}
{ "latency" : , "province" : "新疆", "timestamp" : "2016-10-28" }
{ "index": {}}
{ "latency" : , "province" : "新疆", "timestamp" : "2016-10-29" }
{ "index": {}}
{ "latency" : , "province" : "新疆", "timestamp" : "2016-10-29" }
{ "index": {}}
{ "latency" : , "province" : "新疆", "timestamp" : "2016-10-28" }
{ "index": {}}
{ "latency" : , "province" : "新疆", "timestamp" : "2016-10-28" }
{ "index": {}}
{ "latency" : , "province" : "新疆", "timestamp" : "2016-10-29" } PUT /website
{
"mappings": {
"logs": {
"properties": {
"latency": {
"type": "long"
},
"province": {
"type": "keyword"
},
"timestamp": {
"type": "date"
}
}
}
}
} GET website/_search
{
"size": ,
"aggs": {
"latency_time": {
"percentiles": {
"field": "latency",
"percents": [
,
, ]
}
},
"avg_time": {
"avg": {
"field": "latency"
}
}
}
}
GET /website/logs/_search
{
"size": ,
"aggs": {
"latency_percentiles": {
"percentiles": {
"field": "latency",
"percents": [
,
, ]
}
},
"latency_avg": {
"avg": {
"field": "latency"
}
}
}
} GET /website/logs/_search
{
"size": ,
"aggs": {
"group_by_province": {
"terms": {
"field": "province"
},
"aggs": {
"latency_percentile_ranks": {
"percentile_ranks": {
"field": "latency",
"values": [
, ]
}
}
}
}
}
} GET /_stats/fielddata?fields=* GET /_nodes/stats/indices/fielddata?fields=* GET /_nodes/stats/indices/fielddata?level=indices&fields=* POST /test_index/_mapping/test_type
{
"properties": {
"test_field": {
"type": "string",
"fielddata": {
"loading" : "eager_global_ordinals"
}
}
}
} POST /test_index/_mapping/test_type
{
"properties": {
"test_field": {
"type": "string",
"fielddata": {
"loading" : "eager"
}
}
}
}
PUT /website/users/
{
"name": "小鱼儿",
"email": "xiaoyuer@sina.com",
"birthday": "1980-01-01"
} PUT /website/blogs/
{
"title": "我的第一篇博客",
"content": "这是我的第一篇博客,开通啦!!",
"userId":
} GET website/blogs/_search
GET /website/users/_search
{
"query": {
"term": {
"name.keyword": {
"value": "小鱼儿"
}
}
}
} GET /website/blogs/_search
{
"query": {
"constant_score": {
"filter": {
"terms": {
"userId": [ ]
}
}
}
}
}
GET /website/blogs/_search
{ "query": {
"constant_score": {
"filter": {
"terms": {
"userId": [ ]
}
}
}
}
}
DELETE website PUT website/users/
{
"name":"小鱼儿",
"email":"xiaoyuer@sina.com",
"birthday":"1989-01-01"
}
PUT website/blogs/
{
"title":"小鱼儿的第一篇博客",
"ontent":"大家好,我是小鱼儿。。。",
"userInfo":{
"userId":,
"userName":"小鱼儿"
}
}
GET /website/blogs/_search
{
"query": {
"term": {
"userInfo.userName.keyword": {
"value": "小鱼儿"
}
}
}
} PUT /website/users/
{
"name": "黄药师",
"email": "huangyaoshi@sina.com",
"birthday": "1970-10-24"
} PUT /website/blogs/
{
"title": "我是黄药师",
"content": "我是黄药师啊,各位同学们!!!",
"userInfo": {
"userId": ,
"userName": "黄药师"
}
} PUT /website/users/
{
"name": "花无缺",
"email": "huawuque@sina.com",
"birthday": "1980-02-02"
} PUT /website/blogs/
{
"title": "花无缺的身世揭秘",
"content": "大家好,我是花无缺,所以我的身世是。。。",
"userInfo": {
"userId": ,
"userName": "花无缺"
}
} GET /website/blogs/_search
{
"size": ,
"aggs": {
"group_by_name": {
"terms": {
"field": "userInfo.userName.keyword"
},
"aggs": {
"top_blogs": {
"top_hits": {
"_source": {
"include": "title"
},
"size":
}
}
}
}
}
} GET /website/blogs/_search
{
"size": ,
"aggs": {
"group_by_username": {
"terms": {
"field": "userInfo.userName.keyword"
},
"aggs": {
"top_blogs": {
"top_hits": {
"_source": {
"include": "title"
},
"size":
}
}
}
}
}
} DELETE /fs/lock/global POST /fs/file//_update
{
"doc": {
"name": "README1.txt"
}
}
DELETE /fs/lock/global PUT /website/blogs/
{
"title": "花无缺发表的一篇帖子",
"content": "我是花无缺,大家要不要考虑一下投资房产和买股票的事情啊。。。",
"tags": [ "投资", "理财" ],
"comments": [
{
"name": "小鱼儿",
"comment": "什么股票啊?推荐一下呗",
"age": ,
"stars": ,
"date": "2016-09-01"
},
{
"name": "黄药师",
"comment": "我喜欢投资房产,风,险大收益也大",
"age": ,
"stars": ,
"date": "2016-10-22"
}
]
} GET /website/blogs/_search
{
"query": {
"bool": {
"must": [
{ "match": { "comments.name": "黄药师" }},
{ "match": { "comments.age": }}
]
}
}
} PUT /website
{
"mappings": {
"blogs": {
"properties": {
"comments": {
"type": "nested",
"properties": {
"name": { "type": "string" },
"comment": { "type": "string" },
"age": { "type": "short" },
"stars": { "type": "short" },
"date": { "type": "date" }
}
}
}
}
}
} PUT /website/blogs/
{
"title": "花无缺发表的一篇帖子",
"content": "我是花无缺,大家要不要考虑一下投资房产和买股票的事情啊。。。",
"tags": [ "投资", "理财" ],
"comments": [
{
"name": "小鱼儿",
"comment": "什么股票啊?推荐一下呗",
"age": ,
"stars": ,
"date": "2016-09-01"
},
{
"name": "黄药师",
"comment": "我喜欢投资房产,风,险大收益也大",
"age": ,
"stars": ,
"date": "2016-10-22"
}
]
}
GET /website/blogs/_search GET /website/blogs/_search
{
"query": {
"bool": {
"must": [
{ "match": { "comments.name": "黄药师" }},
{ "match": { "comments.age": }}
]
}
}
}
GET /website/blogs/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "花无缺"
},
"nested": {
"path": "comments",
"query": {
"bool": {
"must": [
{
"match": {
"comments.name":"黄药师"
}
}
]
}
}
}
}
]
}
}
} GET /website/blogs/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "花无缺"
}
},
{
"nested": {
"path": "comments",
"query": {
"bool": {
"must": [
{
"match": {
"comments.name": "黄药师"
}
},
{
"match": {
"comments.age":
}
}
]
}
}
}
}
]
}
}
} GET /website/blogs/_search
{
"size": ,
"aggs": {
"comments_path": {
"nested": {
"path": "comments"
},
"aggs": {
"group_by_comments_date": {
"date_histogram": {
"field": "comments.date",
"interval": "month",
"format": "yyyy-MM"
},
"aggs": {
"avg_stars": {
"avg": {
"field": "comments.stars"
}
}
}
}
}
}
}
}
GET /website/blogs/_search
{
"size": ,
"aggs": {
"comments_path": {
"nested": {
"path": "comments"
},
"aggs": {
"group_by_comments_age": {
"histogram": {
"field": "comments.age",
"interval":
},
"aggs": {
"reverse_path": {
"reverse_nested": {},
"aggs": {
"group_by_tags": {
"terms": {
"field": "tags.keyword"
}
}
}
}
}
}
}
}
}
} DELETE company GET /company/_search
PUT /company
{
"mappings": {
"rd_center": {},
"employee": {
"_parent": {
"type": "rd_center"
}
}
}
} POST /company/rd_center/_bulk
{ "index": { "_id": "" }}
{ "name": "北京研发总部", "city": "北京", "country": "中国" }
{ "index": { "_id": "" }}
{ "name": "上海研发中心", "city": "上海", "country": "中国" }
{ "index": { "_id": "" }}
{ "name": "硅谷人工智能实验室", "city": "硅谷", "country": "美国" } PUT /company/employee/?parent=
{
"name": "张三",
"birthday": "1970-10-24",
"hobby": "爬山"
} POST /company/employee/_bulk
{ "index": { "_id": , "parent": "" }}
{ "name": "李四", "birthday": "1982-05-16", "hobby": "游泳" }
{ "index": { "_id": , "parent": "" }}
{ "name": "王二", "birthday": "1979-04-01", "hobby": "爬山" }
{ "index": { "_id": , "parent": "" }}
{ "name": "赵五", "birthday": "1987-05-11", "hobby": "骑马" }
GET /company/rd_center/_search
{
"query": {
"has_child": {
"type": "employee",
"query": {
"range": {
"birthday": {
"gte": "1980-01-01"
}
}
}
}
}
} GET /company/rd_center/_search
{
"query": {
"has_child": {
"type": "employee",
"query": {
"range": {
"birthday": {
"gte": "1980-01-01"
}
}
}
}
}
}
GET /company/rd_center/_search
{
"query": {
"has_child": {
"type": "employee",
"query": {
"match": {
"name": "张三"
}
}
}
}
} GET /company/rd_center/_search
{
"query": {
"has_child": {
"type": "employee",
"min_children": ,
"query": {
"match_all": {}
}
}
}
}
GET /company/employee/_search
{
"query": {
"has_parent": {
"parent_type": "rd_center",
"query": {
"term": {
"country.keyword":"中国"
}
}
}
}
}
GET /company/rd_center/_search
{
"size": ,
"aggs": {
"group_by_country": {
"terms": {
"field": "country.keyword"
},
"aggs": {
"group_by_child_employee": {
"children": {
"type": "employee"
},
"aggs": {
"group_by_hobby": {
"terms": {
"field": "hobby.keyword"
}
}
}
}
}
}
}
}
GET /company/rd_center/_search
{
"aggs": {
"group_by_country": {
"terms": {
"field": "country.keyword"
},
"aggs": {
"group_by_child_employee": {
"children": {
"type": "employee"
},
"aggs": {
"group_by_hobby": {
"terms": {
"field": "hobby.keyword" }
}
}
}
}
}
}
} DELETE company
PUT /company
{
"mappings": {
"country": {},
"rd_center": {
"_parent": {
"type": "country"
}
},
"employee": {
"_parent": {
"type": "rd_center"
}
}
}
} POST /company/country/_bulk
{ "index": { "_id": "" }}
{ "name": "中国" }
{ "index": { "_id": "" }}
{ "name": "美国" } POST /company/rd_center/_bulk
{ "index": { "_id": "", "parent": "" }}
{ "name": "北京研发总部" }
{ "index": { "_id": "", "parent": "" }}
{ "name": "上海研发中心" }
{ "index": { "_id": "", "parent": "" }}
{ "name": "硅谷人工智能实验室" } PUT /company/employee/?parent=&routing=
{
"name": "张三",
"dob": "1970-10-24",
"hobby": "爬山"
} GET /company/country/_search
{
"query": {
"has_child": {
"type": "rd_center",
"query": {
"has_child": {
"type": "employee",
"query": {
"match": {
"hobby": "爬山"
}
}
}
}
}
}
}
GET /company/country/_search
{
"query": {
"has_child": {
"type": "rd_center",
"query": {
"has_child": {
"type": "employee",
"query": {
"match": {
"hobby": "爬山"
}
}
}
}
}
}
}
DELETE blog_website
PUT /blog_website
{
"mappings": {
"blogs": {
"properties": {
"title": {
"type": "text",
"analyzer": "ik_max_word"
},
"content": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
} PUT /blog_website/blogs/
{
"title": "我的第一篇博客",
"content": "大家好,这是我写的第一篇博客,特别喜欢这个博客网站!!!"
}
GET blog_website/blogs/_search
{
"query": {
"match": {
"title": "博客"
} },
"highlight": {
"fields": {
"title":{}
}
}
} GET /blog_website/blogs/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"title": "博客"
}
},{
"match": {
"content": "博客"
}
}
]
} },
"highlight": {
"fields": {
"title":{},
"content":{}
}
}
}
GET /blog_website/blogs/_search/template
{
"inline":{
"query":{
"match":{
"{{field}}":"{{value}}"
}
}
},"params": {
"field":"title",
"value":"博客"
}
} GET /blog_website/blogs/_search/template
{
"inline": "{\"query\": {\"match\": {{#toJson}}matchCondition{{/toJson}}}}",
"params": {
"matchCondition": {
"title": "博客"
}
}
}
GET /blog_website/blogs/_search/template
{
"inline": {
"query": {
"match": {
"title": "{{#join delimiter=' '}}titles{{/join delimiter=' '}}"
}
}
},
"params": {
"titles": ["博客", "网站"]
}
} # delete news_website PUT /news_website
{
"mappings": {
"news" : {
"properties" : {
"title" : {
"type": "text",
"analyzer": "ik_max_word",
"fields": {
"suggest" : {
"type" : "completion",
"analyzer": "ik_max_word"
}
}
},
"content": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
} PUT /news_website/news/
{
"title": "大话西游电影",
"content": "大话西游的电影时隔20年即将在2017年4月重映"
}
PUT /news_website/news/
{
"title": "大话西游小说",
"content": "某知名网络小说作家已经完成了大话西游同名小说的出版"
}
PUT /news_website/news/
{
"title": "大话西游手游",
"content": "网易游戏近日出品了大话西游经典IP的手游,正在火爆内测中"
}
PUT /news_website
{
"mappings": {
"news" : {
"properties" : {
"title" : {
"type": "text",
"analyzer": "ik_max_word",
"fields": {
"suggest" : {
"type" : "completion",
"analyzer": "ik_max_word"
}
}
},
"content": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
}
PUT /news_website2
{
"mappings": {
"news":{
"properties": {
"title":{
"type": "text",
"analyzer": "ik_max_word",
"fields": {
"suggest":{
"type": "completion",
"analyzer": "ik_max_word"
}
}
},
"content":{
"type": "text",
"analyzer": "ik_max_word",
"fields": {
"suggest":{
"type": "completion",
"analyzer": "ik_max_word"
}
}
}
}
}
}
}
POST /news_website2/news/
{
"title": "大话西游电影",
"content": "大话西游的电影时隔20年即将在2017年4月重映"
}
GET /news_website2/news/_search
{
"query": {
"match": {
"title": "西游"
}
},
"explain": true
} GET /news_website2/news/_search
{
"suggest":{
"suggest":{
"prefix":"大话西游",
"completion":{
"field":"title.suggest"
}
}
}
} #
GET /news_website/news/_search
{
"query": {
"prefix": {
"title": {
"value": "大话西游"
}
}
},
"_source": ["title","content"],
"explain": true
} GET /news_website/news/_search
{
"suggest": {
"my-suggest" : {
"prefix" : "大话西游",
"completion" : {
"field" : "title.suggest"
}
}
}
}
DELETE my_index
PUT my_index
{
"mappings": {
"my_type": {
"dynamic_templates": [
{
"integers": {
"match_mapping_type": "long",
"mapping": {
"type": "integer"
}
}
},
{
"strings": {
"match_mapping_type": "string",
"mapping": {
"type": "text",
"fields": {
"raw": {
"type": "keyword",
"ignore_above":
}
}
}
}
}
]
}
}
} PUT /my_index/my_type/
{
"test_long": ,
"test_string": "hello world"
} GET my_index/_mapping/my_type PUT /my_index
{
"mappings": {
"my_type": {
"dynamic_templates": [
{
"string_as_integer": {
"match_mapping_type": "string",
"match": "long_*",
"unmatch": "*_text",
"mapping": {
"type": "integer"
}
}
}
]
}
}
} DELETE car_shop
PUT /car_shop
{
"mappings": {
"cars": {
"properties": {
"brand": {
"type": "text",
"analyzer": "ik_max_word",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"name": {
"type": "text",
"analyzer": "ik_max_word",
"fields": {
"raw": {
"type": "keyword"
}
}
}
}
}
}
} GET car_shop/_search PUT /car_shop/cars/
{
"brand": "奔驰",
"name": "奔驰C200",
"price": ,
"produce_date": "2017-01-05"
} PUT /car_shop/sales/
{
"brand": "宝马",
"name": "宝马320",
"price": ,
"produce_date": "2017-01-01",
"sale_price": ,
"sale_date": "2017-01-21"
} PUT /car_shop/sales/
{
"brand": "宝马",
"name": "宝马320",
"price": ,
"produce_date": "2017-01-01",
"sale_price": ,
"sale_date": "2017-01-21"
} GET /car_shop/sales/_search DELETE products PUT products
{
"settings": {
"number_of_shards":
}
} POST /products/products/_bulk
{ "index": { "_id": }}
{ "productID" : "XHDK-A-1293-#fJ3","desc":"iPhone" }
{ "index": { "_id": }}
{ "productID" : "KDKE-B-9947-#kL5","desc":"iPad" }
{ "index": { "_id": }}
{ "productID" : "JODL-X-1937-#pV7","desc":"MBP" }
POST _analyze
{
"text":"iPhone"
} GET /products/products/_search
{
"query": {
"term": {
"desc.keyword": {
"value": "iPhone"
}
}
}
}
GET /products/products/_search
{
"explain": true,
"query": {
"constant_score": {
"filter": {
"term": {
"desc.keyword": "iPhone"
}
} }
}
} PUT /website
{
"mappings": {
"article": {
"properties": {
"title": {
"type": "text",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
},
"fielddata": true
},
"content": {
"type": "text"
},
"post_date": {
"type": "date"
},
"author_id": {
"type": "long"
}
}
}
}
} PUT /blogs/blogs/
{
"title": "Quick brown rabbits",
"body": "Brown rabbits are commonly see."
} PUT /blogs/blogs/
{
"title": "Keeping pets healthy",
"body": "My quick brown fox eats rabbits on a regular basis."
} POST /blogs/blogs/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"title": "Brown fox"
}
},
{
"match": {
"body": "Brown fox"
}
}
]
}
}
} GET /blogs/blogs/_search
{
"query": {
"dis_max": {
"tie_breaker": 0.7,
"boost": 1.2,
"queries": [
{
"match": {
"title": "Brown fox"
}
},
{
"match": {
"body": "Brown fox"
}
}
]
}
}
}
POST blogs/blogs/_search
{
"query": {
"dis_max": {
"queries": [
{ "match": { "title": "Quick pets" }},
{ "match": { "body": "Quick pets" }}
],
"tie_breaker": 0.2
}
}
}
GET articles/_search
DELETE articles PUT articles
{
"mappings": {
"articles"{
"properties": {
"title_completion":{
"type": "completion"
}
}
}
}
} PUT /articles
{
"mappings": {
"articles": {
"properties": {
"title_completion":{
"type": "completion"
}
}
}
}
} POST articles/articles/_bulk
{ "index" : { } }
{ "title_completion": "lucene is very cool"}
{ "index" : { } }
{ "title_completion": "Elasticsearch builds on top of lucene"}
{ "index" : { } }
{ "title_completion": "Elasticsearch rocks"}
{ "index" : { } }
{ "title_completion": "elastic is the company behind ELK stack"}
{ "index" : { } }
{ "title_completion": "Elk stack rocks"}
{ "index" : {} } POST articles/_search?pretty
{
"size": ,
"suggest": {
"article-suggester": {
"prefix": "e ",
"completion": {
"field": "title_completion"
}
}
}
}
GET articles/articles/_search
{
"explain": true,
"suggest":{
"articles-suggest":{
"prefix":"elk",
"completion":{
"field":"title_completion"
}
}
}
} PUT /articles
{
"mappings": {
"articles": {
"properties": {
"title_completion":{
"type": "completion"
}
}
}
}
}
DELETE comments
PUT comments
PUT comments/_mapping PUT comments
{
"mappings": {
"comments":{
"properties": {
"comment_autocomplete":{
"type": "completion",
"contexts":[{
"type":"category",
"name":"comment_category"
}]
}
}
}
}
}
DELETE comments GET comments/_search PUT comments
{
"mappings": {
"comments": {
"properties": {
"comment_autocomplete": {
"type": "completion",
"contexts": [
{
"type": "category",
"name": "comment_category"
}
]
}
}
}
}
} POST comments/comments/
{
"comment":"I love the star war movies",
"comment_autocomplete":{
"input":["star wars"],
"contexts":{
"comment_category":"movies"
}
}
}
POST comments/comments/
{
"comment":"Where can I find a Starbucks",
"comment_autocomplete":{
"input":["starbucks"],
"contexts":{
"comment_category":"coffee"
}
}
}
GET comments/_search
{
"size": ,
"suggest": {
"my_suggest": {
"prefix": "sta",
"completion":{
"field":"comment_autocomplete",
"contexts":{
"comment_category":"movies"
}
}
}
}
} GET comments/_search
{
"size": ,
"suggest": {
"my_suggest": {
"prefix": "sta",
"completion":{
"field":"comment_autocomplete",
"contexts":{
"comment_category":"coffee"
}
}
}
}
} GET /_cat/health?v GET _cluster/health GET /_cat/indices?v GET /_cat/nodes?v get cars/_search put car POST /car/transactions/_bulk
{ "index": {}}
{ "price" : , "color" : "red", "make" : "honda", "sold" : "2014-10-28" }
{ "index": {}}
{ "price" : , "color" : "red", "make" : "honda", "sold" : "2014-11-05" }
{ "index": {}}
{ "price" : , "color" : "green", "make" : "ford", "sold" : "2014-05-18" }
{ "index": {}}
{ "price" : , "color" : "blue", "make" : "toyota", "sold" : "2014-07-02" }
{ "index": {}}
{ "price" : , "color" : "green", "make" : "toyota", "sold" : "2014-08-19" }
{ "index": {}}
{ "price" : , "color" : "red", "make" : "honda", "sold" : "2014-11-05" }
{ "index": {}}
{ "price" : , "color" : "red", "make" : "bmw", "sold" : "2014-01-01" }
{ "index": {}}
{ "price" : , "color" : "blue", "make" : "ford", "sold" : "2014-02-12" } #an'yan'se'fen'zu安颜色分组 GET /car/transactions/_search
{
"size": ,
"aggs": {
"group_by_color": {
"terms": {
"field": "color.keyword"
}
}
}
} #先按颜色分组后计算平均价格
GET /car/transactions/_search
{
"size": ,
"aggs": {
"group_by_color": {
"terms": {
"field": "color.keyword"
},
"aggs": {
"avg_color": {
"avg": {
"field": "price"
}
}
}
} }
}
#select color, count(color) as cnt, avg(price) as avg_price from cars group by color order by cnt desc; #统计每种颜色汽车制造商的分布dsl实现
GET /car/transactions/_search
{
"size": ,
"aggs": {
"group_by_color": {
"terms": {
"field": "color.keyword"
},
"aggs": {
"group_by_make": {
"terms": {
"field": "make.keyword"
}
}
}
}
}
} GET _stats/fielddata?human&fields=my_join_field GET _nodes/stats/indices/fielddata?human&fields=my_join_field
GET /forum/article/_search
{
"query": {
"match_phrase": {
"title": {
"query": "java spark",
"slop":
}
}
}
} GET /forum/article/_search
{
"query": {
"match_phrase": {
"content": {
"query": "spark data",
"slop":
}
}
}
} GET /forum/article/_search
{
"query": {
"match_phrase": {
"content": {
"query": "data spark",
"slop":
}
}
}
}
#索引1的分片移动到索引2 POST /_cluster/reroute
{
"commands": [
{
"move": {
"index": "my_index_name",
"shard": ,
"from_node": "node1",
"to_node": "node2"
}
},
{
"allocate": {
"index": "my_index_name",
"shard": ,
"node": "node3"
}
}
]
}
#动态更新最小节点数。 PUT /_cluster/settings
{
"persistent": {
"discovery.zen.minimum_master_nodes":
}
} GET /forum/article/_search
{
"query": {
"match_phrase": {
"content": {
"query": "java best",
"slop":
}
}
}
} GET /books/_search
{
"query": {
"constant_score": {
"filter": {
"range": {
"price": {
"gte": ,
"lt":
}
}
}
}
}
} GET /books/_search
{
"query": {
"constant_score": {
"filter": {
"exists": {
"field": "title"
}
}
}
}
} GET /books/_search
{
"query": {
"constant_score": {
"filter": {
"bool": {
"should": [
{
"range": {
"price": {
"gte": ,
"lte":
}
}
}
]
}
},
"boost": 1.2
}
}
}
POST /books/_search
{
"query": {
"match": {
"title": "Java"
}
},
"size": ,
"from": ,
"_source": [
"title",
"language",
"author"
],
"highlight": {
"fields": {
"title": {}
}
}
} POST ik_index/ik_type/
{
"title":"公路局正在治理解放大道路面积水问题"
} GET ik_index/ik_type/_search
{
"query": {
"match_phrase": {
"title": "道路"
}
}
} GET cars/_search GET ik_index/ik_type/_search
{
"profile": "true",
"query": {
"match_phrase": {
"title.ik_my_max": "道路"
}
}
}
GET /_analyze
{
"analyzer": "ik_max_word",
"text":"公路局正在治理解放大道路面积水问题"
} PUT /my_index
{
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": ,
"max_gram":
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
}
} GET /my_index/_analyze
{
"analyzer": "autocomplete",
"text": "quick brown"
} PUT /my_index/_mapping/my_type
{
"properties": {
"title": {
"type": "string",
"analyzer": "autocomplete",
"search_analyzer": "standard"
}
}
} GET /my_index/my_type/_search
{
"query": {
"match_phrase": {
"title": "hello w"
}
}
} PUT my_index
{
"mappings": {
"my_type": {
"properties": {
"title": {
"type": "keyword"
}
}
}
}
} GET my_index/my_type/_search
{
"query": {
"prefix": {
"title": {
"value": "C3"
}
}
}
} GET /forum/article/_search
{
"query": {
"match_phrase": {
"content": {
"query": "spark data",
"slop":
}
}
}
}GET /forum/article/_search
{
"query": {
"match_phrase": {
"title": {
"query": "java spark",
"slop":
}
}
}
} POST /forum/article//_update
{
"doc": {
"content": "spark is best big data solution based on scala ,an programming language similar to java spark"
}
} GET _analyze
{
"text": "hello world, java spark",
"analyzer": "standard"
} PUT /forum/_mapping/article
{
"properties": {
"new_author_first_name": {
"type": "string",
"copy_to": "new_author_full_name"
},
"new_author_last_name": {
"type": "string",
"copy_to": "new_author_full_name"
},
"new_author_full_name": {
"type": "string"
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"new_author_first_name" : "Peter", "new_author_last_name" : "Smith"} } --> Peter Smith
{ "update": { "_id": ""} }
{ "doc" : {"new_author_first_name" : "Smith", "new_author_last_name" : "Williams"} } --> Smith Williams
{ "update": { "_id": ""} }
{ "doc" : {"new_author_first_name" : "Jack", "new_author_last_name" : "Ma"} } --> Jack Ma
{ "update": { "_id": ""} }
{ "doc" : {"new_author_first_name" : "Robbin", "new_author_last_name" : "Li"} } --> Robbin Li
{ "update": { "_id": ""} }
{ "doc" : {"new_author_first_name" : "Tonny", "new_author_last_name" : "Peter Smith"} } --> Tonny Peter Smith GET /forum/article/_search
{
"query": {
"match": {
"new_author_full_name": "Peter Smith"
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"author_first_name" : "Peter", "author_last_name" : "Smith"} }
{ "update": { "_id": ""} }
{ "doc" : {"author_first_name" : "Smith", "author_last_name" : "Williams"} }
{ "update": { "_id": ""} }
{ "doc" : {"author_first_name" : "Jack", "author_last_name" : "Ma"} }
{ "update": { "_id": ""} }
{ "doc" : {"author_first_name" : "Robbin", "author_last_name" : "Li"} }
{ "update": { "_id": ""} }
{ "doc" : {"author_first_name" : "Tonny", "author_last_name" : "Peter Smith"} } GET /forum/article/_search
{
"query": {
"multi_match": {
"query": "Peter Smith",
"type": "most_fields",
"fields": [ "author_first_name", "author_last_name" ]
}
}
}
POST /forum/_mapping/article
{
"properties": {
"sub_title": {
"type": "string",
"analyzer": "english",
"fields": {
"std": {
"type": "string",
"analyzer": "standard"
}
}
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "learning more courses"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "learned a lot of course"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "we have a lot of fun"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "both of them are good"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "haha, hello world"} } GET /forum/article/_search
{
"query": {
"match": {
"sub_title": "learning courses"
}
}
}
GET /forum/article/_search
{
"query": {
"match": {
"sub_title": "learning courses"
}
}
} GET /forum/article/_search
{
"query": {
"dis_max": {
"queries": [
{ "match": { "title": "java beginner" }},
{ "match": { "body": "java beginner" }}
]
}
}
}
GET /forum/article/_search
{
"query": {
"dis_max": {
"queries": [
{ "match": { "title": "java beginner" }},
{ "match": { "body": "java beginner" }}
],
"tie_breaker": 0.3
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"content" : "i like to write best elasticsearch article"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "i think java is the best programming language"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "i am only an elasticsearch beginner"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "elasticsearch and hadoop are all very good solution, i am a beginner"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "spark is best big data solution based on scala ,an programming language similar to java"} }
GET /forum/article/_search
{
"query": {
"bool": {
"should": [
{ "match": { "title": "java solution" }},
{ "match": { "content": "java solution" }}
]
}
}
}
GET /forum/article/_search
{
"query": {
"dis_max": {
"queries": [
{ "match": { "title": "java solution" }},
{ "match": { "content": "java solution" }}
]
}
}
} GET /forum/article/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "blog"
}
}
],
"should": [
{
"match": {
"title": {
"query": "java"
}
}
},
{
"match": {
"title": {
"query": "hadoop"
}
}
},
{
"match": {
"title": {
"query": "elasticsearch"
}
}
},
{
"match": {
"title": {
"query": "spark",
"boost":
}
}
}
]
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java and elasticsearch blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is elasticsearch blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java, elasticsearch, hadoop blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is spark blog"} } POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java and elasticsearch blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is elasticsearch blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java, elasticsearch, hadoop blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is spark blog"} }
GET /forum/article/_search
{
"query": {
"match": {
"title": {
"query": "java elasticsearch",
"operator": "and"
}
}
}
}
GET /forum/article/_search
{
"query": {
"match": {
"title": {
"query": "java elasticsearch",
"operator": "and"
}
}
}
}
GET /forum/article/_search
{
"query": {
"bool": {
"must": { "match": { "title": "java" }},
"must_not": { "match": { "title": "spark" }},
"should": [
{ "match": { "title": "hadoop" }},
{ "match": { "title": "elasticsearch" }}
]
}
}
}
GET /forum/article/_search
{
"query": {
"bool": {
"should": [
{ "match": { "title": "java" }},
{ "match": { "title": "elasticsearch" }},
{ "match": { "title": "hadoop" }},
{ "match": { "title": "spark" }}
],
"minimum_should_match":
}
}
}
GET /books/_search
{
"size": ,
"aggs": {
"grades_stats": {
"stats": {
"field": "price"
}
}
}
} GET /_search
{
"query": {
"bool": {
"should": [
{ "match": { "address": "mill" } },
{ "match": { "address": "lane" } }
]
}
}
} PUT my_index/my_type/
{
"full_text": "Quick Foxes!",
"exact_value": "Quick Foxes!"
} GET my_index/my_type/_search
{
"query": {
"term": {
"exact_value": "Quick Foxes!"
}
}
} GET my_index/my_type/_search
{
"query": {
"term": {
"full_text": "Quick Foxes!"
}
}
}
GET my_index/my_type/_search
{
"query": {
"term": {
"full_text": "foxes"
}
}
} GET my_index/my_type/_search
{
"query": {
"match": {
"full_text": "Quick Foxes!"
}
}
} POST /termtest/termtype/
{
"content":"Name"
} POST /termtest/termtype/
{
"content":"name city"
} GET /termtest/_search
{
"query":
{
"match_all": {}
}
} POST /termtest/_search
{
"query":{
"term":{
"content":"name"
}
}
} POST /termtest/_search
{
"query":{
"match":{
"content":"Name"
}
}
} PUT my_index/my_type/
{
"zuMaker":
{"type":"keyword","index":"false"} } PUT my_index/my_type/
{
"zuName":
{"type":"text","index":"true","boost":"","analyzer":"ik_max_word","search_analyzer":"ik_max_word"} } PUT my_index/my_type/
{
"zuMaker":
{"type":"keyword","index":"false"} } PUT my_index/my_type/
{
"zuName":
{"type":"text","index":"true","boost":"","analyzer":"ik_max_word","search_analyzer":"ik_max_word"} } GET my_index/my_type/_search { "query": { "term": { "zuName": "墙体钢结构" } } } GET my_index/my_type/_search
{ "query": { "term": { "zuMakert": "张三李四" } } } GET my_index/my_type/_search PUT my_index/my_type/
{
"zuMaker":
{
"type": "keyword",
"index": "false",
"content":"张三李四"
} } PUT my_index/my_type/
{
"zuName": {
"type": "text",
"index": "true",
"boost": "",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"content":"墙体钢结构"
}
}
GET my_index/_search { "query": { "term": { "zuMakert": "张三李四" } } } //设置mapping
POST /productindex/product/_mapping?pretty
{
"product": {
"properties": {
"title": {
"type": "string",
"store": "yes"
},
"description": {
"type": "string",
"index": "not_analyzed"
},
"price": {
"type": "double"
},
"onSale": {
"type": "boolean"
},
"type": {
"type": "integer"
},
"createDate": {
"type": "date"
}
}
}
} //新增mapping
POST /productindex/product/_mapping?pretty
{
"product": {
"properties": {
"amount":{
"type":"integer"
}
}
}
} POST /productindex/product/_mapping?pretty
{
"product": {
"properties": {
"onSale":{
"type":"string"
}
}
}
} //设置mapping之后,插入数据
POST /productindex/product/
{
"title" : "John",
"description" : "Smith",
"price" : ,
"onSale" : "" ,
"type": ,
"createDate" : "2017-08-26"
} //精确查找 GET /test_index2/_search
{
"query": {
"match_phrase": {
"title":"Java程序性能优化"
}
}
} //如果我们希望两个字段进行匹配,其中一个字段有这个文档就满足的话,使用multi_match GET /test_index2/_search
{
"query": {
"multi_match": {
"query" : "Java程序性能优化",
"fields" : ["title", "language"]
}
}
} //boolean 查询 GET /test_index2/_search
{
"query": {
"bool": {
"must": {
"term": {
"title": "java"
}
},
"must_not": {
"term": {
"language": "javascript"
}
}
}
}
} //and or 查询 GET /test_index2/_search
{
"query": {
"match": {
"title": {
"query": "Java Python",
"operator": "or" --and
}
}
}
} //range 过滤 GET /_search
{
"query": {
"range": {
"age": {
"gte": ,
"lt":
}
}
}
} #The filtered query has been deprecated and removed in ES 5.0. You should now use the bool/must/filter query instead. {
"query": {
"bool": {
"must": {
"multi_match": {
"operator": "and",
"fields": [
"author",
"title",
"publisher",
"year"
],
"query": "George Orwell"
}
},
"filter": {
"terms": {
"year": [
, ]
}
}
}
}
}
PUT /artists/
{
"settings": {
"analysis": {
"analyzer": {
"user_name_analyzer": {
"tokenizer": "whitespace",
"filter": "pinyin_first_letter_and_full_pinyin_filter"
}
},
"filter": {
"pinyin_first_letter_and_full_pinyin_filter": {
"type": "pinyin",
"keep_first_letter": true,
"keep_full_pinyin": false,
"keep_none_chinese": true,
"keep_original": false,
"limit_first_letter_length": ,
"lowercase": true,
"trim_whitespace": true,
"keep_none_chinese_in_first_letter": true
}
}
}
}
} GET /artists/_analyze
{
"text": ["刘德华 张学友 郭富城 黎明 王传付 四大天王"],
"analyzer": "user_name_analyzer"
} #查询指定条件的数据
#select * from order o where o.price=
GET /my_store/_search
{
"query": {
"bool": {
"must": {
"match_all": { }
},
"filter": {
"term": {
"price" :
}
}
}
}
} PUT /website
{
"mappings": {
"article": {
"properties": {
"title": {
"type": "text",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
},
"fielddata": true
},
"content": {
"type": "text"
},
"post_date": {
"type": "date"
},
"author_id": {
"type": "long"
}
}
}
}
} PUT /website/article/
{
"title": "first article",
"content": "this is my second article",
"post_date": "2017-01-01",
"author_id":
} {
"took": ,
"timed_out": false,
"_shards": {
"total": ,
"successful": ,
"failed":
},
"hits": {
"total": ,
"max_score": ,
"hits": [
{
"_index": "website",
"_type": "article",
"_id": "",
"_score": ,
"_source": {
"title": "first article",
"content": "this is my first article",
"post_date": "2017-02-01",
"author_id":
}
},
{
"_index": "website",
"_type": "article",
"_id": "",
"_score": ,
"_source": {
"title": "second article",
"content": "this is my second article",
"post_date": "2017-01-01",
"author_id":
}
},
{
"_index": "website",
"_type": "article",
"_id": "",
"_score": ,
"_source": {
"title": "third article",
"content": "this is my third article",
"post_date": "2017-03-01",
"author_id":
}
}
]
}
} GET /website/article/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"title.raw": {
"order": "desc"
}
}
]
} GET /_search
{
"query" : {
"bool" : {
"filter" : {
"term" : {
"author_id" :
}
}
}
}
} 当然,也可以是constant_score GET /_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"author_id" :
}
}
}
}
} 、定制排序规则 GET /company/employee/_search
{
"query": {
"constant_score": {
"filter": {
"range": {
"age": {
"gte":
}
}
}
}
},
"sort": [
{
"join_date": {
"order": "asc"
}
}
]
} GET /website/article/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "elasticsearch"
}
}
],
"should": [
{
"match": {
"content": "elasticsearch"
}
}
],
"must_not": [
{
"match": {
"author_id":
}
}
]
}
}
} GET /test_index/_search
{
"query": {
"bool": {
"must": { "match": { "name": "tom" }},
"should": [
{ "match": { "hired": true }},
{ "bool": {
"must": { "match": { "personality": "good" }},
"must_not": { "match": { "rude": true }}
}}
],
"minimum_should_match":
}
}
} 、match all GET /_search
{
"query": {
"match_all": {}
}
} 、match GET /_search
{
"query": { "match": { "title": "my elasticsearch article" }}
} 、multi match GET /test_index/test_type/_search
{
"query": {
"multi_match": {
"query": "test",
"fields": ["test_field", "test_field1"]
}
}
} 、range query GET /company/employee/_search
{
"query": {
"range": {
"age": {
"gte":
}
}
}
} 、term query GET /test_index/test_type/_search
{
"query": {
"term": {
"test_field": "test hello"
}
}
} 、terms query GET /_search
{
"query": { "terms": { "tag": [ "search", "full_text", "nosql" ] }}
}
PUT /company/employee/
{
"address": {
"country": "china",
"province": "jiangsu",
"city": "nanjing"
},
"name": "tom",
"age": ,
"join_date": "2016-01-01"
} PUT /company/employee/
{
"address": {
"country": "china",
"province": "shanxi",
"city": "xian"
},
"name": "marry",
"age": ,
"join_date": "2015-01-01"
} GET /company/employee/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"join_date": "2016-01-01"
}
}
],
"filter": {
"range": {
"age": {
"gte":
}
}
}
}
}
} 、修改mapping 只能创建index时手动建立mapping,或者新增field mapping,但是不能update field mapping PUT /website
{
"mappings": {
"article": {
"properties": {
"author_id": {
"type": "long"
},
"title": {
"type": "text",
"analyzer": "english"
},
"content": {
"type": "text"
},
"post_date": {
"type": "date"
},
"publisher_id": {
"type": "text",
"index": "not_analyzed"
}
}
}
}
} PUT /website
{
"mappings": {
"article": {
"properties": {
"author_id": {
"type": "text"
}
}
}
}
}
PUT /website/_mapping/article
{
"properties" : {
"new_field" : {
"type" : "string",
"index": "not_analyzed"
}
}
} GET /website/_mapping
、测试mapping GET /website/_analyze
{
"field": "content",
"text": "my-dogs"
} GET website/_analyze
{
"field": "new_field",
"text": "my dogs"
} {
"error": {
"root_cause": [
{
"type": "remote_transport_exception",
"reason": "[4onsTYV][127.0.0.1:9300][indices:admin/analyze[s]]"
}
],
"type": "illegal_argument_exception",
"reason": "Can't process field [new_field], Analysis requests are only supported on tokenized fields"
},
"status":
} PUT /website/article/
{
"post_date": "2017-01-01",
"title": "my first article",
"content": "this is my first article in this website",
"author_id":
} PUT /website/article/
{
"post_date": "2017-01-02",
"title": "my second article",
"content": "this is my second article in this website",
"author_id":
} PUT /website/article/
{
"post_date": "2017-01-03",
"title": "my third article",
"content": "this is my third article in this website",
"author_id":
} 尝试各种搜索 GET /website/_mapping/article {
"website": {
"mappings": {
"article": {
"properties": {
"author_id": {
"type": "long"
},
"content": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above":
}
}
},
"post_date": {
"type": "date"
},
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above":
}
}
}
}
}
}
}
} GET /_search {
"took": ,
"timed_out": false,
"_shards": {
"total": ,
"successful": ,
"failed":
},
"hits": {
"total": ,
"max_score": ,
"hits": [
{
"_index": ".kibana",
"_type": "config",
"_id": "5.2.0",
"_score": ,
"_source": {
"buildNum":
}
}
]
}
}
#bulk语法 POST /_bulk
{ "delete": { "_index": "test_index", "_type": "test_type", "_id": "" }}
{ "create": { "_index": "test_index", "_type": "test_type", "_id": "" }}
{ "test_field": "test12" }
{ "index": { "_index": "test_index", "_type": "test_type", "_id": "" }}
{ "test_field": "replaced test2" }
{ "update": { "_index": "test_index", "_type": "test_type", "_id": "", "_retry_on_conflict" : } }
{ "doc" : {"test_field2" : "bulk test1"} } POST /test_index/_bulk
{ "delete": { "_type": "test_type", "_id": "" }}
{ "create": { "_type": "test_type", "_id": "" }}
{ "test_field": "test12" }
{ "index": { "_type": "test_type" }}
{ "test_field": "auto-generate id test" }
{ "index": { "_type": "test_type", "_id": "" }}
{ "test_field": "replaced test2" }
{ "update": { "_type": "test_type", "_id": "", "_retry_on_conflict" : } }
{ "doc" : {"test_field2" : "bulk test1"} } POST /test_index/test_type/_bulk
{ "delete": { "_id": "" }}
{ "create": { "_id": "" }}
{ "test_field": "test12" }
{ "index": { }}
{ "test_field": "auto-generate id test" }
{ "index": { "_id": "" }}
{ "test_field": "replaced test2" }
{ "update": { "_id": "", "_retry_on_conflict" : } }
{ "doc" : {"test_field2" : "bulk test1"} } GET /_mget
{
"docs" : [
{
"_index" : "test_index",
"_type" : "test_type",
"_id" :
},
{
"_index" : "test_index",
"_type" : "test_type",
"_id" :
}
]
} {
"docs": [
{
"_index": "test_index",
"_type": "test_type",
"_id": "",
"_version": ,
"found": true,
"_source": {
"test_field1": "test field1",
"test_field2": "test field2"
}
},
{
"_index": "test_index",
"_type": "test_type",
"_id": "",
"_version": ,
"found": true,
"_source": {
"test_content": "my test"
}
}
]
} ()如果查询的document是一个index下的不同type种的话 GET /test_index/_mget
{
"docs" : [
{
"_type" : "test_type",
"_id" :
},
{
"_type" : "test_type",
"_id" :
}
]
} ()如果查询的数据都在同一个index下的同一个type下,最简单了 GET /test_index/test_type/_mget
{
"ids": [, ]
} PUT /test_index/test_type/
{
"num": ,
"tags": []
}
POST /test_index/test_type//_update
{
"script" : "ctx._source.num+=1"
} {
"_index": "test_index",
"_type": "test_type",
"_id": "",
"_version": ,
"found": true,
"_source": {
"num": ,
"tags": []
}
} POST /test_index/test_type//_update
{
"script": {
"lang": "groovy",
"file": "test-add-tags",
"params": {
"new_tag": "tag1"
}
}
}
POST /test_index/test_type//_update
{
"doc": {
"num":
}
}
GET /ecommerce/product/_search
{
"aggs": {
"group_by_tags": {
"terms": { "field": "tags" }
}
}
} GET /car/_search GET /car/_search
{
"aggs": {
"group_by_color": {
"terms": { "field": "color" }
}
}
}
PUT /ecommerce/_mapping/product
{
"properties": {
"tags": {
"type": "text",
"fielddata": true
}
}
}
GET /ecommerce/product/_search
{
"size": ,
"aggs": {
"all_tags": {
"terms": { "field": "tags" }
}
}
}
GET /ecommerce/product/_search
{
"size": ,
"query": {
"match": {
"name": "yagao"
}
},
"aggs": {
"all_tags": {
"terms": {
"field": "tags"
}
}
}
}
GET /ecommerce/product/_search
{
"size": ,
"aggs" : {
"group_by_tags" : {
"terms" : { "field" : "tags" },
"aggs" : {
"avg_price" : {
"avg" : { "field" : "price" }
}
}
}
}
} GET /ecommerce/product/_search
{
"size": ,
"aggs" : {
"all_tags" : {
"terms" : { "field" : "tags", "order": { "avg_price": "desc" } },
"aggs" : {
"avg_price" : {
"avg" : { "field" : "price" }
}
}
}
}
} GET /ecommerce/product/_search
{
"size": ,
"aggs": {
"group_by_price": {
"range": {
"field": "price",
"ranges": [
{
"from": ,
"to":
},
{
"from": ,
"to":
},
{
"from": ,
"to":
}
]
},
"aggs": {
"group_by_tags": {
"terms": {
"field": "tags"
},
"aggs": {
"average_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
}
}
GET /ecommerce/product/_search
{
"query": { "match_all": {} }
} GET /ecommerce/product/_search
{
"query" : {
"match" : {
"name" : "yagao"
}
},
"sort": [
{ "price": "desc" }
]
}
GET /ecommerce/product/_search
{
"query": { "match_all": {} },
"from": ,
"size":
}
GET /ecommerce/product/_search
{
"query": { "match_all": {} },
"_source": ["name", "price"]
} GET /ecommerce/product/_search
{
"query" : {
"bool" : {
"must" : {
"match" : {
"name" : "yagao"
}
},
"filter" : {
"range" : {
"price" : { "gt" : }
}
}
}
}
} GET /ecommerce/product/_search
{
"query" : {
"match" : {
"producer" : "yagao producer"
}
}
}
GET /ecommerce/product/_search
{
"query" : {
"match_phrase" : {
"producer" : "yagao producer"
}
}
}
GET /ecommerce/product/_search
{
"query" : {
"match" : {
"producer" : "producer"
}
},
"highlight": {
"fields" : {
"producer" : {}
}
}
}
POST /forum/article/_bulk
{ "index": { "_id": }}
{ "articleID" : "XHDK-A-1293-#fJ3", "userID" : , "hidden": false, "postDate": "2017-01-01" }
{ "index": { "_id": }}
{ "articleID" : "KDKE-B-9947-#kL5", "userID" : , "hidden": false, "postDate": "2017-01-02" }
{ "index": { "_id": }}
{ "articleID" : "JODL-X-1937-#pV7", "userID" : , "hidden": false, "postDate": "2017-01-01" }
{ "index": { "_id": }}
{ "articleID" : "QQPX-R-3956-#aD8", "userID" : , "hidden": true, "postDate": "2017-01-02" } GET /forum/_mapping/article {
"forum": {
"mappings": {
"article": {
"properties": {
"articleID": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above":
}
}
},
"hidden": {
"type": "boolean"
},
"postDate": {
"type": "date"
},
"userID": {
"type": "long"
}
}
}
}
}
}
GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"userID" :
}
}
}
}
} GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"hidden" : false
}
}
}
}
}
GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"postDate" : "2017-01-01"
}
}
}
}
} GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"articleID" : "XHDK-A-1293-#fJ3"
}
}
}
}
}
GET /forum/_analyze
{
"field": "articleID",
"text": "XHDK-A-1293-#fJ3"
} DELETE /forum PUT /forum
{
"mappings": {
"article": {
"properties": {
"articleID": {
"type": "keyword"
}
}
}
}
} POST /forum/article/_bulk
{ "index": { "_id": }}
{ "articleID" : "XHDK-A-1293-#fJ3", "userID" : , "hidden": false, "postDate": "2017-01-01" }
{ "index": { "_id": }}
{ "articleID" : "KDKE-B-9947-#kL5", "userID" : , "hidden": false, "postDate": "2017-01-02" }
{ "index": { "_id": }}
{ "articleID" : "JODL-X-1937-#pV7", "userID" : , "hidden": false, "postDate": "2017-01-01" }
{ "index": { "_id": }}
{ "articleID" : "QQPX-R-3956-#aD8", "userID" : , "hidden": true, "postDate": "2017-01-02" } GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"articleID" : "XHDK-A-1293-#fJ3"
}
}
}
}
}
PUT test_index/test_type/
{
"test_field":"test1"
} GET test_index/test_type/_search PUT test_index/test_type/?version=
{
"test_field":"test3"
} GET website/_search
GET website/_mapping/blogs GET /website/_analyze
{
"field": "content",
"text": "my-dogs"
} GET /_analyze
{
"analyzer": "ik_max_word",
"text": "中华人民共和国"
} GET /_analyze
{
"analyzer": "standard",
"text": "中华人民共和国"
} GET /_analyze
{
"analyzer": "index_ansj",
"text": "中华人民共和国"
} GET /jd_item/_mapping GET /jd_item/jd_item/_search
{
"query": {
"match": {
"title": "飞利浦"
}
}
} GET /jd_item/jd_item/_search
{
"from":,
"size":,
"query": {
"bool": {
"must": [
{
"query_string": {
"default_field": "title",
"query": "飞利浦"
}
},
{
"query_string": {
"default_field": "id",
"query": ""
}
}
]
}
}
} GET /jd_item/jd_item/_search
{
"query": {
"match": {
"title": "飞利"
}
}
}
GET /tvs/sales/_search
{
"size" : ,
"aggs":{
"price":{
"histogram":{
"field": "price",
"interval":
},
"aggs":{
"revenue": {
"sum": {
"field" : "price"
}
}
}
}
}
} GET /tvs/sales/_search
{
"size": ,
"query": {
"term": {
"brand": {
"value": "长虹"
}
}
},
"aggs": {
"recent_150d": {
"filter": {
"range": {
"sold_date": {
"gte": "now-150d"
}
}
},
"aggs": {
"recent_150d_avg_price": {
"avg": {
"field": "price"
}
}
}
},
"recent_140d": {
"filter": {
"range": {
"sold_date": {
"gte": "now-140d"
}
}
},
"aggs": {
"recent_140d_avg_price": {
"avg": {
"field": "price"
}
}
}
},
"recent_130d": {
"filter": {
"range": {
"sold_date": {
"gte": "now-130d"
}
}
},
"aggs": {
"recent_130d_avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
} GET /spnews/news/_search
{
"query": {
"multi_match": {
"query": "足球",
"fields": [
"content^1.0",
"title^1.0"
],
"type": "best_fields",
"operator": "OR",
"slop": ,
"prefix_length": ,
"max_expansions": ,
"lenient": false,
"zero_terms_query": "NONE",
"boost":
}
},
"highlight": {
"pre_tags": [
"<font style='color:red'>"
],
"post_tags": [
"</font>"
],
"fields": {
"title": {},
"content": {}
}
}
}
GET /spnews/news/_search
{
"from": ,
"size": ,
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"match": {
"productCommonName": {
"query": "感冒药",
"type": "boolean",
"operator": "AND",
"boost":
}
}
},
{
"match": {
"productName": {
"query": "感冒药",
"type": "boolean",
"operator": "AND",
"boost":
}
}
},
{
"match": {
"productChnNo": {
"query": "感冒药",
"type": "boolean",
"operator": "AND",
"boost":
}
}
},
{
"match": {
"proCatalogName": {
"query": "感冒药",
"type": "boolean",
"operator": "AND",
"boost":
}
}
},
{
"match": {
"productBrandName": {
"query": "感冒药",
"type": "boolean",
"operator": "AND",
"boost":
}
}
},
{
"match": {
"productBrandName1": {
"query": "感冒药",
"type": "boolean",
"operator": "AND",
"boost":
}
}
},
{
"match": {
"productKeyword": {
"query": "感冒药",
"type": "boolean",
"operator": "AND",
"boost":
}
}
}
]
}
},
{
"bool": {
"should": [
{
"range": {
"saleScore": {
"from": ,
"to": null,
"include_lower": false,
"include_upper": true,
"boost":
}
}
},
{
"range": {
"saleScore": {
"from": null,
"to": ,
"include_lower": true,
"include_upper": false,
"boost":
}
}
}
]
}
}
]
}
},
"post_filter": {
"bool": {
"must_not": {
"term": {
"ecPrice": -
}
}
}
},
"sort": [
{
"stock": {
"order": "desc"
}
},
{
"_score": {
"order": "desc"
}
}
],
"highlight": {
"pre_tags": [
"<em>"
],
"post_tags": [
"</em>"
],
"fields": {
"productName": {
"fragment_size":
}
}
}
}
GET /test_index/test_type/_search
{
"query": {
"match": {
"search_field": "test"
}
},
"aggs": {
"group_by_agg_field": {
"terms": {
"field": "agg_field"
}
}
}
} GET /website/users/_search
{
"query": {
"term": {
"name.keyword": {
"value": "小鱼儿"
}
}
}
} GET /forum/_mapping/article {
"forum": {
"mappings": {
"article": {
"properties": {
"articleID": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above":
}
}
},
"hidden": {
"type": "boolean"
},
"postDate": {
"type": "date"
},
"userID": {
"type": "long"
}
}
}
}
}
} GET /forum/article/_search POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"tag" : ["java", "hadoop"]} }
{ "update": { "_id": ""} }
{ "doc" : {"tag" : ["java"]} }
{ "update": { "_id": ""} }
{ "doc" : {"tag" : ["hadoop"]} }
{ "update": { "_id": ""} }
{ "doc" : {"tag" : ["java", "elasticsearch"]} } GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"terms" : {
"tag" : ["java"]
}
}
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"tag_cnt" : } }
{ "update": { "_id": ""} }
{ "doc" : {"tag_cnt" : } }
{ "update": { "_id": ""} }
{ "doc" : {"tag_cnt" : } }
{ "update": { "_id": ""} }
{ "doc" : {"tag_cnt" : } } POST /forum/article/_bulk
{ "index": { "_id": }}
{ "articleID" : "XHDK-A-1293-#fJ3", "userID" : , "hidden": false, "postDate": "2017-01-01" }
{ "index": { "_id": }}
{ "articleID" : "KDKE-B-9947-#kL5", "userID" : , "hidden": false, "postDate": "2017-01-02" }
{ "index": { "_id": }}
{ "articleID" : "JODL-X-1937-#pV7", "userID" : , "hidden": false, "postDate": "2017-01-01" }
{ "index": { "_id": }}
{ "articleID" : "QQPX-R-3956-#aD8", "userID" : , "hidden": true, "postDate": "2017-01-02" }
GET /forum/article/_search GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"bool": {
"must": [
{
"term": {
"tag_cnt":
}
},
{
"terms": {
"tag": ["java"]
}
}
]
}
}
}
}
} GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"hidden" : false
}
}
}
}
} GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"postDate" : "2017-01-01"
}
}
}
}
} GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"articleID" : "XHDK-A-1293-#fJ3"
}
}
}
}
} GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"articleID.keyword" : "XHDK-A-1293-#fJ3"
}
}
}
}
}
POST /forum/article/_bulk
{ "index": { "_id": }}
{ "articleID" : "XHDK-A-1293-#fJ3", "userID" : , "hidden": false, "postDate": "2017-01-01" }
{ "index": { "_id": }}
{ "articleID" : "KDKE-B-9947-#kL5", "userID" : , "hidden": false, "postDate": "2017-01-02" }
{ "index": { "_id": }}
{ "articleID" : "JODL-X-1937-#pV7", "userID" : , "hidden": false, "postDate": "2017-01-01" }
{ "index": { "_id": }}
{ "articleID" : "QQPX-R-3956-#aD8", "userID" : , "hidden": true, "postDate": "2017-01-02" }
GET /forum/article/_search
{
"query" : {
"constant_score" : {
"filter" : {
"term" : {
"articleID" : "XHDK-A-1293-#fJ3"
}
}
}
}
} GET /forum/article/_search
{
"query": {
"dis_max": {
"queries": [
{ "match": { "title": "java beginner" }},
{ "match": { "content": "java beginner" }}
]
}
}
}
GET /forum/article/_search
{
"query": {
"dis_max": {
"queries": [
{ "match": { "title": "java beginner" }},
{ "match": { "content": "java beginner" }}
],
"tie_breaker": 0.3
}
}
}
GET /my_index/my_type/_search
{
"query": {
"match_phrase_prefix": {
"title": "hello d"
}
}
} GET /my_index/my_type/_search
{
"query": {
"fuzzy": {
"text": {
"value": "surprize",
"fuzziness":
}
}
}
} GET /forum/article/_search
{
"query": {
"multi_match": {
"query": "Peter Smith",
"type": "most_fields",
"fields": [ "author_first_name", "author_last_name" ]
}
}
} GET /forum/article/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"content": "java"
}
},
{
"match": {
"content": "spark"
}
},
{
"bool": {
"should": [
{
"match": {
"content": "solution"
}
},
{
"match": {
"content": "beginner"
}
}
]
}
}
]
}
}
}
GET /forum/article/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"content": "java"
}
}
],
"must_not": [
{
"match": {
"content": "spark"
}
}
]
}
}
} GET /forum/article/_search
{
"query": {
"boosting": {
"positive": {
"match": {
"content": "java"
}
},
"negative": {
"match": {
"content": "spark"
}
},
"negative_boost": 0.2
}
}
} GET /forum/article/_search
{
"query": {
"bool": {
"should": [
{
"constant_score": {
"query": {
"match": {
"title": "java"
}
}
}
},
{
"constant_score": {
"query": {
"match": {
"title": "spark"
}
}
}
}
]
}
}
}
{
"took": ,
"timed_out": false,
"_shards": {
"total": ,
"successful": ,
"failed":
},
"hits": {
"total": ,
"max_score": 0.6931472,
"hits": [
{
"_index": "forum",
"_type": "article",
"_id": "",
"_score": 0.6931472,
"_source": {
"articleID": "KDKE-B-9947-#kL5",
"userID": ,
"hidden": false,
"postDate": "2017-01-02",
"tag": [
"java"
],
"tag_cnt": ,
"view_cnt": ,
"title": "this is java blog",
"content": "i think java is the best programming language",
"sub_title": "learned a lot of course",
"author_first_name": "Smith",
"author_last_name": "Williams"
}
},
{
"_index": "forum",
"_type": "article",
"_id": "",
"_score": 0.5753642,
"_source": {
"articleID": "XHDK-A-1293-#fJ3",
"userID": ,
"hidden": false,
"postDate": "2017-01-01",
"tag": [
"java",
"hadoop"
],
"tag_cnt": ,
"view_cnt": ,
"title": "this is java and elasticsearch blog",
"content": "i like to write best elasticsearch article",
"sub_title": "learning more courses",
"author_first_name": "Peter",
"author_last_name": "Smith"
}
},
{
"_index": "forum",
"_type": "article",
"_id": "",
"_score": 0.51623213,
"_source": {
"articleID": "DHJK-B-1395-#Ky5",
"userID": ,
"hidden": false,
"postDate": "2017-03-01",
"tag": [
"elasticsearch"
],
"tag_cnt": ,
"view_cnt": ,
"title": "this is spark blog",
"content": "spark is best big data solution based on scala ,an programming language similar to java",
"sub_title": "haha, hello world",
"author_first_name": "Tonny",
"author_last_name": "Peter Smith"
}
}
]
}
} PUT /tvs
{
"mappings": {
"sales": {
"properties": {
"price": {
"type": "long"
},
"color": {
"type": "keyword"
},
"brand": {
"type": "keyword"
},
"sold_date": {
"type": "date"
}
}
}
}
} POST /tvs/sales/_bulk
{ "index": {}}
{ "price" : , "color" : "红色", "brand" : "长虹", "sold_date" : "2016-10-28" }
{ "index": {}}
{ "price" : , "color" : "红色", "brand" : "长虹", "sold_date" : "2016-11-05" }
{ "index": {}}
{ "price" : , "color" : "绿色", "brand" : "小米", "sold_date" : "2016-05-18" }
{ "index": {}}
{ "price" : , "color" : "蓝色", "brand" : "TCL", "sold_date" : "2016-07-02" }
{ "index": {}}
{ "price" : , "color" : "绿色", "brand" : "TCL", "sold_date" : "2016-08-19" }
{ "index": {}}
{ "price" : , "color" : "红色", "brand" : "长虹", "sold_date" : "2016-11-05" }
{ "index": {}}
{ "price" : , "color" : "红色", "brand" : "三星", "sold_date" : "2017-01-01" }
{ "index": {}}
{ "price" : , "color" : "蓝色", "brand" : "小米", "sold_date" : "2017-02-12" } GET /tvs/sales/_search
{
"size" : ,
"aggs" : {
"popular_colors" : {
"terms" : {
"field" : "color"
}
}
}
} GET /tvs/sales/_search
{
"size": ,
"query": {
"constant_score": {
"filter": {
"range": {
"price": {
"gte":
}
}
}
}
},
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
}
}
}
GET /tvs/sales/_search
{
"size" : ,
"aggs" : {
"months" : {
"date_histogram": {
"field": "sold_date",
"interval": "month"
},
"aggs": {
"distinct_colors" : {
"cardinality" : {
"field" : "brand"
}
}
}
}
}
} PUT /blog_website
{
"mappings": {
"blogs": {
"properties": {
"title": {
"type": "text",
"analyzer": "ik_max_word"
},
"content": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
} PUT /blog_website/blogs/
{
"title": "我的第一篇博客",
"content": "大家好,这是我写的第一篇博客,特别喜欢这个博客网站!!!"
} GET /blog_website/blogs/_search
{
"query": {
"match": {
"title": "博客"
}
},
"highlight": {
"fields": {
"title": {}
}
}
} GET /blog_website/blogs/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"title": "博客"
}
},
{
"match": {
"content": "博客"
}
}
]
}
},
"highlight": {
"fields": {
"title": {},
"content": {}
}
}
} PUT /news_website
{
"mappings": {
"news" : {
"properties" : {
"title" : {
"type": "text",
"analyzer": "ik_max_word",
"fields": {
"suggest" : {
"type" : "completion",
"analyzer": "ik_max_word"
}
}
},
"content": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
} PUT /news_website_pinyin
{
"mappings": {
"news_pinyin" : {
"properties" : {
"title" : {
"type": "text",
"analyzer": "pinyin_analyzer",
"fields": {
"suggest" : {
"type" : "completion",
"analyzer": "pinyin_analyzer"
}
}
},
"content": {
"type": "text",
"analyzer": "pinyin_analyzer"
}
}
}
}
} PUT /medcl1/
{
"index" : {
"analysis" : {
"analyzer" : {
"ngram_pinyin_analyzer" : {
"tokenizer" : "keyword",
"filter" : ["full_pinyin_with_space","word_delimiter","shingle","remove_whitespace"]
}, "my_pinyin_analyzer" : {
"tokenizer" : "keyword",
"filter" : ["full_pinyin_no_space"]
}
},
"filter" :{
"full_pinyin_no_space" : {
"type" : "pinyin",
"first_letter" : "none",
"padding_char" : ""
},"full_pinyin_with_space" : {
"type" : "pinyin",
"first_letter" : "none",
"padding_char" : " "
},
"my_edge_ngram_tokenizer" : {
"type" : "edgeNGram",
"min_gram" : "",
"max_gram" : "",
"token_chars": [ "letter", "digit" ]
},
"remove_whitespace": {
"type": "pattern_replace",
"pattern": "\\s+",
"replacement":""
}
}
}
}
} POST medcl1/type/_mapping
{
"properties": {
"name1":{
"type": "multi_field",
"fields": {
"pinyin":{
"type": "string",
"analyzer": "ngram_pinyin_analyzer"
}, "full_pinyin":{
"type": "string",
"analyzer": "my_pinyin_analyzer"
},
"first_letter":{
"type": "string",
"analyzer": "pinyin_first_letter"
},
"name1":{
"type": "string",
"analyzer": "ik_max_word"
}
}
}
}
} GET medcl1/_mapping POST medcl1/type3/
{
"name1":"刘德华"
}
POST medcl1/type3/
{
"name1":"刘斌"
}
POST medcl1/type3/
{
"name1":"张三"
}
POST medcl1/type3/
{
"name1":"李四"
}
POST medcl1/type3/
{
"name1":"刘德志"
} POST medcl1/_search?size=
{
"query": {
"query_string": {
"fields": ["name1","name1.full_pinyin","name1.pinyin","name1.first_letter"],
"query": "刘德华",
"default_operator": "AND"
}
}
} PUT /search_text
{
"settings": {
"refresh_interval": "5s",
"number_of_shards": ,
"number_of_replicas": ,
"analysis": {
"filter": {
"edge_ngram_filter": {
"type": "edge_ngram",
"min_gram": ,
"max_gram":
},
"pinyin_full_filter": {
"type": "pinyin",
"keep_first_letter": false,
"keep_separate_first_letter": false,
"keep_full_pinyin": true,
"keep_original": false,
"limit_first_letter_length": ,
"lowercase": true
},
"pinyin_simple_filter": {
"type": "pinyin",
"keep_first_letter": true,
"keep_separate_first_letter": false,
"keep_full_pinyin": false,
"keep_original": false,
"limit_first_letter_length": ,
"lowercase": true
}
},
"analyzer": {
"pinyiSimpleIndexAnalyzer": {
"type": "custom",
"tokenizer": "keyword",
"filter": [
"pinyin_simple_filter",
"edge_ngram_filter",
"lowercase"
]
},
"pinyiFullIndexAnalyzer": {
"type": "custom",
"tokenizer": "keyword",
"filter": [
"pinyin_full_filter",
"lowercase"
]
}
}
}
}
} PUT /search_text/_mapping/list
{
"properties": {
"name": {
"type": "keyword",
"fields": {
"fpy": {
"type": "text",
"index": true,
"analyzer": "pinyiFullIndexAnalyzer"
},
"spy": {
"type": "text",
"index": true,
"analyzer": "pinyiSimpleIndexAnalyzer"
}
}
}
}
} PUT /search_text/list/
{
"name":"刘德华"
} PUT /search_text/list/
{
"name":"天命"
}
PUT /search_text/list/
{
"name":"你好明天"
}
POST /search_text/list/_search
{
"query":{
"match":{
"name.fpy":{
"query":"liudehua",
"operator": "and"
}
}
}
} GET /news_website/news/_mapping PUT /news_website/news/
{
"title": "大话西游电影dhxy",
"content": "大话西游的电影时隔20年即将在2017年4月重映"
}
PUT /news_website/news/
{
"title": "大话西游小说dhxy",
"content": "某知名网络小说作家已经完成了大话西游同名小说的出版"
}
PUT /news_website/news/
{
"title": "大话西游手游dhxy",
"content": "网易游戏近日出品了大话西游经典IP的手游,正在火爆内测中"
} GET /news_website/news/_search
{
"suggest": {
"my-suggest" : {
"prefix" : "dhxy",
"completion" : {
"field" : "title.suggest"
}
}
}
}
GET /news_website/news/_search
{
"query": {
"match": {
"content": "大话西游电影"
}
}
} PUT /my_index
{
"mappings": {
"my_type": {
"properties": {
"text": {
"type": "text",
"term_vector": "with_positions_offsets_payloads",
"store" : true,
"analyzer" : "fulltext_analyzer"
},
"fullname": {
"type": "text",
"analyzer" : "fulltext_analyzer"
}
}
}
},
"settings" : {
"index" : {
"number_of_shards" : ,
"number_of_replicas" :
},
"analysis": {
"analyzer": {
"fulltext_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"type_as_payload"
]
}
}
}
}
} PUT /my_index/my_type/
{
"fullname" : "Leo Li",
"text" : "hello test test test "
} PUT /my_index/my_type/
{
"fullname" : "Leo Li",
"text" : "other hello test ..."
} GET /my_index/my_type//_termvectors
{
"fields" : ["text"],
"offsets" : true,
"payloads" : true,
"positions" : true,
"term_statistics" : true,
"field_statistics" : true
} {
"_index": "my_index",
"_type": "my_type",
"_id": "",
"_version": ,
"found": true,
"took": ,
"term_vectors": {
"text": {
"field_statistics": {
"sum_doc_freq": ,
"doc_count": ,
"sum_ttf":
},
"terms": {
"hello": {
"doc_freq": ,
"ttf": ,
"term_freq": ,
"tokens": [
{
"position": ,
"start_offset": ,
"end_offset": ,
"payload": "d29yZA=="
}
]
},
"test": {
"doc_freq": ,
"ttf": ,
"term_freq": ,
"tokens": [
{
"position": ,
"start_offset": ,
"end_offset": ,
"payload": "d29yZA=="
},
{
"position": ,
"start_offset": ,
"end_offset": ,
"payload": "d29yZA=="
},
{
"position": ,
"start_offset": ,
"end_offset": ,
"payload": "d29yZA=="
}
]
}
}
}
}
}
GET /my_index/my_type//_termvectors
{
"fields" : ["fullname"],
"offsets" : true,
"positions" : true,
"term_statistics" : true,
"field_statistics" : true
}GET /my_index/my_type/_termvectors
{
"doc" : {
"fullname" : "Leo Li",
"text" : "hello test test test"
},
"fields" : ["text"],
"offsets" : true,
"payloads" : true,
"positions" : true,
"term_statistics" : true,
"field_statistics" : true
}
GET /company/rd_center/_search
{
"size": ,
"aggs": {
"group_by_country": {
"terms": {
"field": "country.keyword"
},
"aggs": {
"group_by_child_employee": {
"children": {
"type": "employee"
},
"aggs": {
"group_by_hobby": {
"terms": {
"field": "hobby.keyword"
}
}
}
}
}
}
}
} GET /movies/_search
{
"from": ,
"size": ,
"query": {
"match_all": {}
}
} GET /forum/_search GET /forum/_mapping/article GET /forum/_search
{
"query": {
"constant_score": {
"filter": {
"term": {
"userID": ""
}
}
}
}
} GET /forum/_search
{
"query": {
"bool": {
"must_not": [
{
"term": {
"postDate": {
"value": "2017-01-02"
}
}
}
],
"should": [
{
"term": {
"postDate": "2017-01-01"
}
},
{
"term": {
"articleID": "XHDK-A-1293-#fJ3"
}
}
]
}
}
} GET /forum/_search
{
"query": {
"bool": {
"should": [
{
"term": {
"postDate":"2017-01-01" }
},{
"term": {
"articleID":"XHDK-A-1293-#fJ3"
}
}
]
}
}
}
GET /forum/_search
{
"query": {
"bool": {
"should": [
{
"term": {
"postDate":"2017-01-01"
}
},{
"term": {
"articleID":"XHDK-A-1293-#fJ3"
}
}
],
"must_not": [
{
"term": {
"postDate":"2017-01-02"
}
}
]
}
}
}
GET /forum/_search
{
"query": {
"constant_score": {
"filter": {
"bool": {
"should": [
{
"term": {
"articleID": "XHDK-A-1293-#fJ3"
}
}
],
"bool": {
"must": [
{
"term": {
"articleID": "JODL-X-1937-#pV7"
}
}
]
}
}
}
}
}
} GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"bool": {
"should": [
{
"term": {
"articleID": "XHDK-A-1293-#fJ3"
}
},
{
"bool": {
"must": [
{
"term": {
"articleID": "JODL-X-1937-#pV7"
}
},
{
"term": {
"postDate": "2017-01-01"
}
}
]
}
}
]
}
}
}
}
} #搜索帖子ID为XHDK-A--#fJ3,或者是帖子ID为JODL-X--#pV7而且发帖日期为2017--01的帖子 GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"bool": {
"should": [
{
"term": {
"articleID": "XHDK-A-1293-#fJ3"
}
},
{
"bool": {
"must": [
{
"term": {
"postDate": "2017-01-01"
}
},
{
"term":{
"articleID": "JODL-X-1937-#pV7"
}
}
]
}
}
]
}
}
}
}
}
GET /forum/article/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"postDate": "2017-01-01"
}
}
],
"should": [
{
"term": {
"articleID": "XHDK-A-1293-#fJ3"
}
}, {
"term": {"articleID": "JODL-X-1937-#pV7"
}
}
]
}
}
}
GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"terms": {
"articleID": [
"KDKE-B-9947-#kL5",
"QQPX-R-3956-#aD8"
]
}
}
}
}
} GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"terms": {
"articleID": [
"KDKE-B-9947-#kL5",
"QQPX-R-3956-#aD8"
]
}
}
}
}
}
GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"terms": {
"tag" : ["java"]
}
}
}
}
} GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"bool": {
"must": [
{
"term": {
"tag_cnt":
}
},
{
"terms": {
"tag": ["java"]
}
}
]
}
}
}
}
} GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"bool": {
"must":[
{
"term":{
"tag_cnt":
}
},{
"terms":{
"tag": ["java"]
}
}
]
}
}
}
}
} GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"range": {
"view_cnt": {
"gte": ,
"lte":
}
}
} }
}
}
#最近一个月的帖子
GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"range": {
"postDate": {
"gt": "2017-03-10||-30d"
}
}
}
}
}
} GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"range": {
"postDate": {
"gte": "now-30d"
}
}
}
}
}
}
GET /forum/article/_mapping
GET /forum/article/_search
{
"query": {
"match": {
"title": "java elasticsearch"
}
}
} GET /forum/article/_search
{
"query": {
"match": {
"title": {
"query": "java elasticsearch",
"operator": "and"
}
}
}
}
GET /forum/article/_search
{
"query": {
"match": {
"title":{
"query": "java elasticsearch spark hadoop",
"minimum_should_match": "75%"
}
}
}
}
GET /forum/article/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "java"
}
}
],"must_not": [
{
"match": {
"title": "spark"
}
}
],
"should": [
{
"match": {
"title": "hadoop"
}
},{
"match": {
"title": "elasticsearch"
}
}
]
}
}
}
GET /forum/article/_search
{
"query": {
"bool": {
"must": {
"match": {
"title": "java"
}
},
"must_not": {
"match": {
"title": "spark"
}
},
"should": [
{
"match": {
"title": "hadoop"
}
},
{
"match": {
"title": "elasticsearch"
}
}
]
}
}
}
GET /forum/article/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"title": "java"
}
},
{
"match": {
"title": "elasticsearch"
}
},
{
"match": {
"title": "spark"
}
},
{
"match": {
"title": "hadoop"
}
} ],
"minimum_should_match":
}
}
} GET /forum/article/_search
{
"query": {
"match": {
"title": {
"query": "",
"operator": "and"
}
}
}
} GET /forum/article/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "blog"
}
}
],
"should": [
{
"match": {
"title": {
"query": "java"
}
}
},
{
"match": {
"title": {
"query": "hadoop"
}
}
},
{
"match": {
"title": {
"query": "elasticsearch"
}
}
},
{
"match": {
"title": {
"query": "spark",
"boost":
}
}
}
]
}
}
} GET /forum/article/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "blog"
}
}
],
"should": [
{
"match": {
"title": {
"query": "java"
}
}
},
{
"match": {
"title": {
"query": "hadoop"
}
}
},
{
"match": {
"title": {
"query": "elasticsearch"
}
}
},
{
"match": {
"title": {
"query": "spark",
"boost":
}
}
}
]
}
}
} GET /forum/article/_search
{
"query": {
"bool": {
"should": [
{ "match": { "title": "java solution" }},
{ "match": { "content": "java solution" }}
]
}
}
} GET /forum/article/_search
POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"content" : "i like to write best elasticsearch article"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "i think java is the best programming language"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "i am only an elasticsearch beginner"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "elasticsearch and hadoop are all very good solution, i am a beginner"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "spark is best big data solution based on scala ,an programming language similar to java"} }
GET /forum/article/_search
{
"query":{
"bool": {
"should": [
{
"match": {
"content": "java solution"
}
},{
"match": {
"title": "java solution"
}
}
]
}
}
}
GET /forum/article/_search GET /forum/article/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"content": "java solution"
}
},
{
"match": {
"title": "java solution"
}
}
]
}
}
} GET /forum/article/_search
{
"query": {
"dis_max": {
"queries": [
{
"match": {
"title": "java solution"
}
},{
"match": {
"content": "java solution"
}
}
]
}
}
} GET /forum/article/_search
{
"query": {
"dis_max": {
"queries": [
{ "match": { "title": "java beginner" }},
{ "match": { "content": "java beginner" }}
],
"tie_breaker": 0.3 }
}
} GET /forum/article/_search
{
"query": {
"multi_match": {
"query": "java solution",
"fields": [ "title^2", "content" ],
"tie_breaker": 0.3,
"minimum_should_match": "50%" }
}
} GET /forum/article/_search
{
"query": {
"match": {
"sub_title": "learning courses"
}
}
} GET /forum/article/_search
{
"query": {
"match": {
"sub_title": "Tlearning courses"
}
}
}
GET /forum/article/_mapping POST /forum/_mapping/article
{
"properties": {
"sub_title": {
"type": "string",
"analyzer": "english",
"fields": {
"std": {
"type": "string",
"analyzer": "standard"
}
}
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "learning more courses"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "learned a lot of course"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "we have a lot of fun"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "both of them are good"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "haha, hello world"} } GET /forum/article/_search GET /forum/article/_search
{
"query": {
"match": {
"sub_title": "learning courses"
}
}
} POST /forum/_mapping/article
{
"properties": {
"sub_title": {
"type": "string",
"analyzer": "english",
"fields": {
"std": {
"type": "string",
"analyzer": "standard"
}
}
}
}
}
post /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "learning more courses"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "learned a lot of course"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "we have a lot of fun"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "both of them are good"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "haha, hello world"} } GET /forum/article/_search
{
"query": {
"match": {
"sub_title": "learning courses"
}
}
}
POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java and elasticsearch blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is elasticsearch blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java, elasticsearch, hadoop blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is spark blog"} } get /forum/article/_search POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java and elasticsearch blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is elasticsearch blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java, elasticsearch, hadoop blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is spark blog"} } POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"tag" : ["java", "hadoop"]} }
{ "update": { "_id": ""} }
{ "doc" : {"tag" : ["java"]} }
{ "update": { "_id": ""} }
{ "doc" : {"tag" : ["hadoop"]} }
{ "update": { "_id": ""} }
{ "doc" : {"tag" : ["java", "elasticsearch"]} } POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java and elasticsearch blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is elasticsearch blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is java, elasticsearch, hadoop blog"} }
{ "update": { "_id": ""} }
{ "doc" : {"title" : "this is spark blog"} } POST /forum/_mapping/article
{
"properties": {
"sub_title": {
"type": "string",
"analyzer": "english",
"fields": {
"std": {
"type": "string",
"analyzer": "standard"
}
}
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "learning more courses"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "learned a lot of course"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "we have a lot of fun"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "both of them are good"} }
{ "update": { "_id": ""} }
{ "doc" : {"sub_title" : "haha, hello world"} } GET /forum/article/_search
{
"query": {
"match": {
"sub_title": "learning courses"
}
}
} GET /forum/article/_search
{
"query": {
"match": {
"sub_title": "learning courses"
}
}
} GET /forum/article/_search
{
"query": {
"multi_match": {
"query": "learning courses",
"type": "most_fields",
"fields": [ "sub_title", "sub_title.std" ]
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"author_first_name" : "Peter", "author_last_name" : "Smith"} }
{ "update": { "_id": ""} }
{ "doc" : {"author_first_name" : "Smith", "author_last_name" : "Williams"} }
{ "update": { "_id": ""} }
{ "doc" : {"author_first_name" : "Jack", "author_last_name" : "Ma"} }
{ "update": { "_id": ""} }
{ "doc" : {"author_first_name" : "Robbin", "author_last_name" : "Li"} }
{ "update": { "_id": ""} }
{ "doc" : {"author_first_name" : "Tonny", "author_last_name" : "Peter Smith"} } GET /forum/article/_search
{
"query": {
"multi_match": {
"query": "Peter Smith",
"type": "most_fields",
"fields": ["author_first_name","author_last_name"]
}
}
} PUT /forum/_mapping/article
{
"properties": {
"new_author_first_name": {
"type": "string",
"copy_to": "new_author_full_name"
},
"new_author_last_name": {
"type": "string",
"copy_to": "new_author_full_name"
},
"new_author_full_name": {
"type": "string"
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"new_author_first_name" : "Peter", "new_author_last_name" : "Smith"} }
{ "update": { "_id": ""} }
{ "doc" : {"new_author_first_name" : "Smith", "new_author_last_name" : "Williams"} }
{ "update": { "_id": ""} }
{ "doc" : {"new_author_first_name" : "Jack", "new_author_last_name" : "Ma"} }
{ "update": { "_id": ""} }
{ "doc" : {"new_author_first_name" : "Robbin", "new_author_last_name" : "Li"} }
{ "update": { "_id": ""} }
{ "doc" : {"new_author_first_name" : "Tonny", "new_author_last_name" : "Peter Smith"} } GET /forum/article/_search
{
"query": {
"match": {
"new_author_full_name": "Peter Smith"
}
}
}
GET /forum/article/_search
{
"from": ,
"size": ,
"query": {
"match": {
"content": "java "
}
}
}
GET /forum/article/_search
{
"query": {
"match_phrase": {
"content": "java spark"
}
}
} POST /forum/article//_update
{
"doc": {
"content": "spark is best big data solution based on scala ,an programming language similar to java spark"
}
} GET /_analyze
{
"text": "hello world, java spark",
"analyzer": "standard"
} GET /forum/article/_search
{
"query": {
"match_phrase": {
"content": "java spark"
}
}
} GET /forum/article/_search
{
"query": {
"match_all": {}
}
} GET /forum/article/_search
{
"query": {
"match_phrase": {
"content": {
"query": "java best",
"slop":
}
}
}
}
GET /forum/article/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"content": "java spark"
}
}
],
"should": [
{
"match_phrase": {
"content":{
"query": "java spark",
"slop":
}
}
}
]
}
}
}
GET /forum/article/_search
{
"query": {
"match": {
"content": "java spark"
}
},
"rescore": {
"window_size": ,
"query": {
"rescore_query": {
"match_phrase": {
"content": {
"query": "java spark",
"slop":
}
}
}
}
}
} GET /forum/article/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"title": {
"query": "java spark",
"boost":
}
}
},
{
"match":{ "content": "java spark" }
}
]
}
}
} GET /forum/article/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"title": {
"query": "java spark",
"boost":
}
}
},
{
"match": {
"content": "java spark"
}
}
]
}
}
} POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"content" : "i like to write best elasticsearch article"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "i think java is the best programming language"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "i am only an elasticsearch beginner"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "elasticsearch and hadoop are all very good solution, i am a beginner"} }
{ "update": { "_id": ""} }
{ "doc" : {"content" : "spark is best big data solution based on scala ,an programming language similar to java"} } POST /forum/article/_bulk
{ "update": { "_id": ""} }
{ "doc" : {"follower_num" : } }
{ "update": { "_id": ""} }
{ "doc" : {"follower_num" : } }
{ "update": { "_id": ""} }
{ "doc" : {"follower_num" : } }
{ "update": { "_id": ""} }
{ "doc" : {"follower_num" : } }
{ "update": { "_id": ""} }
{ "doc" : {"follower_num" : } } GET /forum/article/_search
{
"query": {
"function_score": {
"query": {
"multi_match": {
"query": "java spark",
"fields": ["tile", "content"]
}
},
"field_value_factor": {
"field": "follower_num",
"modifier": "log1p",
"factor": 0.5
},
"boost_mode": "sum",
"max_boost":
}
}
}
POST /my_index/my_type/_bulk
{ "index": { "_id": }}
{ "text": "Surprise me!"}
{ "index": { "_id": }}
{ "text": "That was surprising."}
{ "index": { "_id": }}
{ "text": "I wasn't surprised."} GET /my_index/my_type/_search
{
"query": {
"fuzzy": {
"text":{
"value": "surprize",
"fuzziness":
}
}
}
} GET /my_index/my_type/_search
{
"query": {
"match": {
"text": {
"query": "SURPIZE ME",
"fuzziness": "AUTO"
}
}
}
}
GET /my_index/my_type/_search
{
"query": {
"match": {
"text":{
"query": "SURPIZE ME"
, "fuzziness": "AUTO",
"operator": "and"
}
}
}
}
GET /my_index/_analyze
{
"text": "男子偷上万元发红包求交女友 被抓获时仍然单身",
"analyzer": "ik_max_word"
} GET /my_index/my_type/_search
{
"query": {
"match": {
"text": "16岁少女结婚好还是单身好?"
}
}
} PUT /my_index
{
"mappings": {
"my_type": {
"properties": {
"text": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
} POST /my_index/my_type/_bulk
{ "index": { "_id": ""} }
{ "text": "男子偷上万元发红包求交女友 被抓获时仍然单身" }
{ "index": { "_id": ""} }
{ "text": "16岁少女为结婚“变”22岁 7年后想离婚被法院拒绝" }
{ "index": { "_id": ""} }
{ "text": "深圳女孩骑车逆行撞奔驰 遭索赔被吓哭(图)" }
{ "index": { "_id": ""} }
{ "text": "女人对护肤品比对男票好?网友神怼" }
{ "index": { "_id": ""} }
{ "text": "为什么国内的街道招牌用的都是红黄配?" } DELETE my_index PUT /my_index
{
"mappings": {
"my_type": {
"properties": {
"text": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
}
POST /my_index/my_type/_bulk
{ "index": { "_id": ""} }
{ "text": "男子偷上万元发红包求交女友 被抓获时仍然单身" }
{ "index": { "_id": ""} }
{ "text": "16岁少女为结婚“变”22岁 7年后想离婚被法院拒绝" }
{ "index": { "_id": ""} }
{ "text": "深圳女孩骑车逆行撞奔驰 遭索赔被吓哭(图)" }
{ "index": { "_id": ""} }
{ "text": "女人对护肤品比对男票好?网友神怼" }
{ "index": { "_id": ""} }
{ "text": "为什么国内的街道招牌用的都是红黄配?" } GET /my_index/my_type/_search
{
"query": {
"match": {
"text": "16岁少女结婚好还是单身好?"
}
}
}
GET /my_index/_analyze
{
"text":"16岁少女结婚好还是单身好",
"analyzer": "ik_max_word"
} PUT /tvs
{
"mappings": {
"sales": {
"properties": {
"price": {
"type": "long"
},
"color": {
"type": "keyword"
},
"brand": {
"type": "keyword"
},
"sold_date": {
"type": "date"
}
}
}
}
}
GET /tvs/sales/_search
{
"size": ,
"aggs": {
"popular_colors": {
"terms": {
"field": "color"
}
}
}
}
GET /tvs/sales/_search
{
"size" : ,
"aggs": {
"colors": {
"terms": {
"field": "color"
},
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
GET /tvs/sales/_search
{
"size": ,
"aggs": {
"colors": {
"terms": {
"field": "color"
},
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
} GET /tvs/sales/_search
{
"size": ,
"aggs": {
"group_by_color": {
"terms": {
"field": "color"
},
"aggs": {
"color_avg_price": {
"avg": {
"field": "price"
}
},
"group_by_brand": {
"terms": {
"field": "brand"
},
"aggs": {
"brand_avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
}
}
GET /tvs/sales/_search
{
"size": ,
"aggs": {
"group_by_color": {
"terms": {
"field": "color"
},
"aggs": {
"color_avg_price": {
"avg": {
"field": "price"
}
},
"group_by_brand": {
"terms": {
"field": "brand"
},
"aggs": {
"brand_avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
}
}
GET /tvs/sales/_search
{
"size": ,
"aggs": {
"colors": {
"terms": {
"field": "color"
},
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
},
"min_price": {
"min": {
"field": "price"
}
},
"max_price": {
"max": {
"field": "price"
}
},
"sum_price": {
"sum": {
"field": "price"
}
}
}
}
}
}
GET /tvs/sales/_search
{
"size": ,
"aggs": {
"colors": {
"terms": {
"field": "color" },
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
},
"max_price":{
"max": {
"field": "price"
}
},
"min_price":{
"min": {
"field": "price"
}
},
"sum_price":{
"sum": {
"field": "price"
}
}
}
}
}
} GET /tvs/sales/_search
{
"size" : ,
"aggs":{
"price":{
"histogram":{
"field": "price",
"interval":
},
"aggs":{
"revenue": {
"sum": {
"field" : "price"
}
}
}
}
}
}
GET /tvs/sales/_search
{
"size": ,
"aggs": {
"price": {
"histogram": {
"field": "price",
"interval":
},
"aggs": {
"revenue":{
"sum": {
"field": "price"
}
}
}
}
}
}
GET /tvs/sales/_search
{
"size": ,
"aggs": {
"sales": {
"date_histogram": {
"field": "date",
"interval": "month",
"format": "yyyy-MM-dd",
"min_doc_count": ,
"extended_bounds":{
"min" : "2016-01-01",
"max" : "2017-12-31"
}
}
}
}
} GET /tvs/sales/_search
{
"size": ,
"aggs": {
"group_by_sold_date": {
"date_histogram": {
"field": "sold_date",
"interval": "quarter",
"format": "yyyy-MM-dd",
"min_doc_count": ,
"extended_bounds": {
"min": "2016-01-01",
"max": "2017-12-31"
}
},
"aggs": {
"group_by_brand": {
"terms": {
"field": "brand"
},
"aggs": {
"sum_price": {
"sum": {
"field": "price"
}
}
}
},
"total_sum_price": {
"sum": {
"field": "price"
}
}
}
}
}
} GET /tvs/sales/_search
{
"size":,
"aggs": {
"group_by_sold_date": {
"date_histogram": {
"field": "date",
"interval": "quarter",
"min_doc_count": ,
"extended_bounds":{
"min": "2016-01-01",
"max": "2017-12-31"
}
},
"aggs": {
"group_by_brand": {
"terms": {
"field": "brand"
},
"aggs": {
"sum_price": {
"sum": {
"field": "price"
}
}
}
},
"total_price":{
"sum": {
"field": "price"
}
}
}
}
}
}
GET /tvs/sales/_search
{
"size": ,
"query": {
"constant_score": {
"filter": {
"range": {
"price": {
"gte":
}
}
}
}
},
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
}
}
} GET /tvs/sales/_search
{
"size" : ,
"aggs" : {
"months" : {
"date_histogram": {
"field": "sold_date",
"interval": "month"
},
"aggs": {
"distinct_colors" : {
"cardinality" : {
"field" : "brand"
}
}
}
}
}
}
#qu'chong去重
GET /tvs/sales/_search
{
"aggs": {
"months": {
"date_histogram": {
"field": "sold_date",
"interval": "month" },
"aggs": {
"distinct_colors": {
"cardinality": {
"field": "brand",
"precision_threshold":
}
}
}
}
}
} POST /website/logs/_bulk
{ "index": {}}
{ "latency" : , "province" : "江苏", "timestamp" : "2016-10-28" }
{ "index": {}}
{ "latency" : , "province" : "江苏", "timestamp" : "2016-10-29" }
{ "index": {}}
{ "latency" : , "province" : "江苏", "timestamp" : "2016-10-29" }
{ "index": {}}
{ "latency" : , "province" : "江苏", "timestamp" : "2016-10-28" }
{ "index": {}}
{ "latency" : , "province" : "江苏", "timestamp" : "2016-10-28" }
{ "index": {}}
{ "latency" : , "province" : "江苏", "timestamp" : "2016-10-29" }
{ "index": {}}
{ "latency" : , "province" : "新疆", "timestamp" : "2016-10-28" }
{ "index": {}}
{ "latency" : , "province" : "新疆", "timestamp" : "2016-10-29" }
{ "index": {}}
{ "latency" : , "province" : "新疆", "timestamp" : "2016-10-29" }
{ "index": {}}
{ "latency" : , "province" : "新疆", "timestamp" : "2016-10-28" }
{ "index": {}}
{ "latency" : , "province" : "新疆", "timestamp" : "2016-10-28" }
{ "index": {}}
{ "latency" : , "province" : "新疆", "timestamp" : "2016-10-29" } PUT /website
{
"mappings": {
"logs": {
"properties": {
"latency": {
"type": "long"
},
"province": {
"type": "keyword"
},
"timestamp": {
"type": "date"
}
}
}
}
} GET website/_search
{
"size": ,
"aggs": {
"latency_time": {
"percentiles": {
"field": "latency",
"percents": [
,
, ]
}
},
"avg_time": {
"avg": {
"field": "latency"
}
}
}
}
GET /website/logs/_search
{
"size": ,
"aggs": {
"latency_percentiles": {
"percentiles": {
"field": "latency",
"percents": [
,
, ]
}
},
"latency_avg": {
"avg": {
"field": "latency"
}
}
}
} GET /website/logs/_search
{
"size": ,
"aggs": {
"group_by_province": {
"terms": {
"field": "province"
},
"aggs": {
"latency_percentile_ranks": {
"percentile_ranks": {
"field": "latency",
"values": [
, ]
}
}
}
}
}
} GET /_stats/fielddata?fields=* GET /_nodes/stats/indices/fielddata?fields=* GET /_nodes/stats/indices/fielddata?level=indices&fields=* POST /test_index/_mapping/test_type
{
"properties": {
"test_field": {
"type": "string",
"fielddata": {
"loading" : "eager_global_ordinals"
}
}
}
} POST /test_index/_mapping/test_type
{
"properties": {
"test_field": {
"type": "string",
"fielddata": {
"loading" : "eager"
}
}
}
}
PUT /website/users/
{
"name": "小鱼儿",
"email": "xiaoyuer@sina.com",
"birthday": "1980-01-01"
} PUT /website/blogs/
{
"title": "我的第一篇博客",
"content": "这是我的第一篇博客,开通啦!!",
"userId":
} GET website/blogs/_search
GET /website/users/_search
{
"query": {
"term": {
"name.keyword": {
"value": "小鱼儿"
}
}
}
} GET /website/blogs/_search
{
"query": {
"constant_score": {
"filter": {
"terms": {
"userId": [ ]
}
}
}
}
}
GET /website/blogs/_search
{ "query": {
"constant_score": {
"filter": {
"terms": {
"userId": [ ]
}
}
}
}
}
DELETE website PUT website/users/
{
"name":"小鱼儿",
"email":"xiaoyuer@sina.com",
"birthday":"1989-01-01"
}
PUT website/blogs/
{
"title":"小鱼儿的第一篇博客",
"ontent":"大家好,我是小鱼儿。。。",
"userInfo":{
"userId":,
"userName":"小鱼儿"
}
}
GET /website/blogs/_search
{
"query": {
"term": {
"userInfo.userName.keyword": {
"value": "小鱼儿"
}
}
}
} PUT /website/users/
{
"name": "黄药师",
"email": "huangyaoshi@sina.com",
"birthday": "1970-10-24"
} PUT /website/blogs/
{
"title": "我是黄药师",
"content": "我是黄药师啊,各位同学们!!!",
"userInfo": {
"userId": ,
"userName": "黄药师"
}
} PUT /website/users/
{
"name": "花无缺",
"email": "huawuque@sina.com",
"birthday": "1980-02-02"
} PUT /website/blogs/
{
"title": "花无缺的身世揭秘",
"content": "大家好,我是花无缺,所以我的身世是。。。",
"userInfo": {
"userId": ,
"userName": "花无缺"
}
} GET /website/blogs/_search
{
"size": ,
"aggs": {
"group_by_name": {
"terms": {
"field": "userInfo.userName.keyword"
},
"aggs": {
"top_blogs": {
"top_hits": {
"_source": {
"include": "title"
},
"size":
}
}
}
}
}
} GET /website/blogs/_search
{
"size": ,
"aggs": {
"group_by_username": {
"terms": {
"field": "userInfo.userName.keyword"
},
"aggs": {
"top_blogs": {
"top_hits": {
"_source": {
"include": "title"
},
"size":
}
}
}
}
}
} DELETE /fs/lock/global POST /fs/file//_update
{
"doc": {
"name": "README1.txt"
}
}
DELETE /fs/lock/global PUT /website/blogs/
{
"title": "花无缺发表的一篇帖子",
"content": "我是花无缺,大家要不要考虑一下投资房产和买股票的事情啊。。。",
"tags": [ "投资", "理财" ],
"comments": [
{
"name": "小鱼儿",
"comment": "什么股票啊?推荐一下呗",
"age": ,
"stars": ,
"date": "2016-09-01"
},
{
"name": "黄药师",
"comment": "我喜欢投资房产,风,险大收益也大",
"age": ,
"stars": ,
"date": "2016-10-22"
}
]
} GET /website/blogs/_search
{
"query": {
"bool": {
"must": [
{ "match": { "comments.name": "黄药师" }},
{ "match": { "comments.age": }}
]
}
}
} PUT /website
{
"mappings": {
"blogs": {
"properties": {
"comments": {
"type": "nested",
"properties": {
"name": { "type": "string" },
"comment": { "type": "string" },
"age": { "type": "short" },
"stars": { "type": "short" },
"date": { "type": "date" }
}
}
}
}
}
} PUT /website/blogs/
{
"title": "花无缺发表的一篇帖子",
"content": "我是花无缺,大家要不要考虑一下投资房产和买股票的事情啊。。。",
"tags": [ "投资", "理财" ],
"comments": [
{
"name": "小鱼儿",
"comment": "什么股票啊?推荐一下呗",
"age": ,
"stars": ,
"date": "2016-09-01"
},
{
"name": "黄药师",
"comment": "我喜欢投资房产,风,险大收益也大",
"age": ,
"stars": ,
"date": "2016-10-22"
}
]
}
GET /website/blogs/_search GET /website/blogs/_search
{
"query": {
"bool": {
"must": [
{ "match": { "comments.name": "黄药师" }},
{ "match": { "comments.age": }}
]
}
}
}
GET /website/blogs/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "花无缺"
},
"nested": {
"path": "comments",
"query": {
"bool": {
"must": [
{
"match": {
"comments.name":"黄药师"
}
}
]
}
}
}
}
]
}
}
} GET /website/blogs/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "花无缺"
}
},
{
"nested": {
"path": "comments",
"query": {
"bool": {
"must": [
{
"match": {
"comments.name": "黄药师"
}
},
{
"match": {
"comments.age":
}
}
]
}
}
}
}
]
}
}
} GET /website/blogs/_search
{
"size": ,
"aggs": {
"comments_path": {
"nested": {
"path": "comments"
},
"aggs": {
"group_by_comments_date": {
"date_histogram": {
"field": "comments.date",
"interval": "month",
"format": "yyyy-MM"
},
"aggs": {
"avg_stars": {
"avg": {
"field": "comments.stars"
}
}
}
}
}
}
}
}
GET /website/blogs/_search
{
"size": ,
"aggs": {
"comments_path": {
"nested": {
"path": "comments"
},
"aggs": {
"group_by_comments_age": {
"histogram": {
"field": "comments.age",
"interval":
},
"aggs": {
"reverse_path": {
"reverse_nested": {},
"aggs": {
"group_by_tags": {
"terms": {
"field": "tags.keyword"
}
}
}
}
}
}
}
}
}
} DELETE company GET /company/_search
PUT /company
{
"mappings": {
"rd_center": {},
"employee": {
"_parent": {
"type": "rd_center"
}
}
}
} POST /company/rd_center/_bulk
{ "index": { "_id": "" }}
{ "name": "北京研发总部", "city": "北京", "country": "中国" }
{ "index": { "_id": "" }}
{ "name": "上海研发中心", "city": "上海", "country": "中国" }
{ "index": { "_id": "" }}
{ "name": "硅谷人工智能实验室", "city": "硅谷", "country": "美国" } PUT /company/employee/?parent=
{
"name": "张三",
"birthday": "1970-10-24",
"hobby": "爬山"
} POST /company/employee/_bulk
{ "index": { "_id": , "parent": "" }}
{ "name": "李四", "birthday": "1982-05-16", "hobby": "游泳" }
{ "index": { "_id": , "parent": "" }}
{ "name": "王二", "birthday": "1979-04-01", "hobby": "爬山" }
{ "index": { "_id": , "parent": "" }}
{ "name": "赵五", "birthday": "1987-05-11", "hobby": "骑马" }
GET /company/rd_center/_search
{
"query": {
"has_child": {
"type": "employee",
"query": {
"range": {
"birthday": {
"gte": "1980-01-01"
}
}
}
}
}
} GET /company/rd_center/_search
{
"query": {
"has_child": {
"type": "employee",
"query": {
"range": {
"birthday": {
"gte": "1980-01-01"
}
}
}
}
}
}
GET /company/rd_center/_search
{
"query": {
"has_child": {
"type": "employee",
"query": {
"match": {
"name": "张三"
}
}
}
}
} GET /company/rd_center/_search
{
"query": {
"has_child": {
"type": "employee",
"min_children": ,
"query": {
"match_all": {}
}
}
}
}
GET /company/employee/_search
{
"query": {
"has_parent": {
"parent_type": "rd_center",
"query": {
"term": {
"country.keyword":"中国"
}
}
}
}
}
GET /company/rd_center/_search
{
"size": ,
"aggs": {
"group_by_country": {
"terms": {
"field": "country.keyword"
},
"aggs": {
"group_by_child_employee": {
"children": {
"type": "employee"
},
"aggs": {
"group_by_hobby": {
"terms": {
"field": "hobby.keyword"
}
}
}
}
}
}
}
}
GET /company/rd_center/_search
{
"aggs": {
"group_by_country": {
"terms": {
"field": "country.keyword"
},
"aggs": {
"group_by_child_employee": {
"children": {
"type": "employee"
},
"aggs": {
"group_by_hobby": {
"terms": {
"field": "hobby.keyword" }
}
}
}
}
}
}
} DELETE company
PUT /company
{
"mappings": {
"country": {},
"rd_center": {
"_parent": {
"type": "country"
}
},
"employee": {
"_parent": {
"type": "rd_center"
}
}
}
} POST /company/country/_bulk
{ "index": { "_id": "" }}
{ "name": "中国" }
{ "index": { "_id": "" }}
{ "name": "美国" } POST /company/rd_center/_bulk
{ "index": { "_id": "", "parent": "" }}
{ "name": "北京研发总部" }
{ "index": { "_id": "", "parent": "" }}
{ "name": "上海研发中心" }
{ "index": { "_id": "", "parent": "" }}
{ "name": "硅谷人工智能实验室" } PUT /company/employee/?parent=&routing=
{
"name": "张三",
"dob": "1970-10-24",
"hobby": "爬山"
} GET /company/country/_search
{
"query": {
"has_child": {
"type": "rd_center",
"query": {
"has_child": {
"type": "employee",
"query": {
"match": {
"hobby": "爬山"
}
}
}
}
}
}
}
GET /company/country/_search
{
"query": {
"has_child": {
"type": "rd_center",
"query": {
"has_child": {
"type": "employee",
"query": {
"match": {
"hobby": "爬山"
}
}
}
}
}
}
}
DELETE blog_website
PUT /blog_website
{
"mappings": {
"blogs": {
"properties": {
"title": {
"type": "text",
"analyzer": "ik_max_word"
},
"content": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
} PUT /blog_website/blogs/
{
"title": "我的第一篇博客",
"content": "大家好,这是我写的第一篇博客,特别喜欢这个博客网站!!!"
}
GET blog_website/blogs/_search
{
"query": {
"match": {
"title": "博客"
} },
"highlight": {
"fields": {
"title":{}
}
}
} GET /blog_website/blogs/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"title": "博客"
}
},{
"match": {
"content": "博客"
}
}
]
} },
"highlight": {
"fields": {
"title":{},
"content":{}
}
}
}
GET /blog_website/blogs/_search/template
{
"inline":{
"query":{
"match":{
"{{field}}":"{{value}}"
}
}
},"params": {
"field":"title",
"value":"博客"
}
} GET /blog_website/blogs/_search/template
{
"inline": "{\"query\": {\"match\": {{#toJson}}matchCondition{{/toJson}}}}",
"params": {
"matchCondition": {
"title": "博客"
}
}
}
GET /blog_website/blogs/_search/template
{
"inline": {
"query": {
"match": {
"title": "{{#join delimiter=' '}}titles{{/join delimiter=' '}}"
}
}
},
"params": {
"titles": ["博客", "网站"]
}
} # delete news_website PUT /news_website
{
"mappings": {
"news" : {
"properties" : {
"title" : {
"type": "text",
"analyzer": "ik_max_word",
"fields": {
"suggest" : {
"type" : "completion",
"analyzer": "ik_max_word"
}
}
},
"content": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
} PUT /news_website/news/
{
"title": "大话西游电影",
"content": "大话西游的电影时隔20年即将在2017年4月重映"
}
PUT /news_website/news/
{
"title": "大话西游小说",
"content": "某知名网络小说作家已经完成了大话西游同名小说的出版"
}
PUT /news_website/news/
{
"title": "大话西游手游",
"content": "网易游戏近日出品了大话西游经典IP的手游,正在火爆内测中"
}
PUT /news_website
{
"mappings": {
"news" : {
"properties" : {
"title" : {
"type": "text",
"analyzer": "ik_max_word",
"fields": {
"suggest" : {
"type" : "completion",
"analyzer": "ik_max_word"
}
}
},
"content": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
}
PUT /news_website2
{
"mappings": {
"news":{
"properties": {
"title":{
"type": "text",
"analyzer": "ik_max_word",
"fields": {
"suggest":{
"type": "completion",
"analyzer": "ik_max_word"
}
}
},
"content":{
"type": "text",
"analyzer": "ik_max_word",
"fields": {
"suggest":{
"type": "completion",
"analyzer": "ik_max_word"
}
}
}
}
}
}
}
POST /news_website2/news/
{
"title": "大话西游电影",
"content": "大话西游的电影时隔20年即将在2017年4月重映"
}
GET /news_website2/news/_search
{
"query": {
"match": {
"title": "西游"
}
},
"explain": true
} GET /news_website2/news/_search
{
"suggest":{
"suggest":{
"prefix":"大话西游",
"completion":{
"field":"title.suggest"
}
}
}
} #
GET /news_website/news/_search
{
"query": {
"prefix": {
"title": {
"value": "大话西游"
}
}
},
"_source": ["title","content"],
"explain": true
} GET /news_website/news/_search
{
"suggest": {
"my-suggest" : {
"prefix" : "大话西游",
"completion" : {
"field" : "title.suggest"
}
}
}
}
DELETE my_index
PUT my_index
{
"mappings": {
"my_type": {
"dynamic_templates": [
{
"integers": {
"match_mapping_type": "long",
"mapping": {
"type": "integer"
}
}
},
{
"strings": {
"match_mapping_type": "string",
"mapping": {
"type": "text",
"fields": {
"raw": {
"type": "keyword",
"ignore_above":
}
}
}
}
}
]
}
}
} PUT /my_index/my_type/
{
"test_long": ,
"test_string": "hello world"
} GET my_index/_mapping/my_type PUT /my_index
{
"mappings": {
"my_type": {
"dynamic_templates": [
{
"string_as_integer": {
"match_mapping_type": "string",
"match": "long_*",
"unmatch": "*_text",
"mapping": {
"type": "integer"
}
}
}
]
}
}
} DELETE car_shop
PUT /car_shop
{
"mappings": {
"cars": {
"properties": {
"brand": {
"type": "text",
"analyzer": "ik_max_word",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"name": {
"type": "text",
"analyzer": "ik_max_word",
"fields": {
"raw": {
"type": "keyword"
}
}
}
}
}
}
} GET car_shop/_search PUT /car_shop/cars/
{
"brand": "奔驰",
"name": "奔驰C200",
"price": ,
"produce_date": "2017-01-05"
} PUT /car_shop/sales/
{
"brand": "宝马",
"name": "宝马320",
"price": ,
"produce_date": "2017-01-01",
"sale_price": ,
"sale_date": "2017-01-21"
} PUT /car_shop/sales/
{
"brand": "宝马",
"name": "宝马320",
"price": ,
"produce_date": "2017-01-01",
"sale_price": ,
"sale_date": "2017-01-21"
} GET /car_shop/sales/_search DELETE products PUT products
{
"settings": {
"number_of_shards":
}
} POST /products/products/_bulk
{ "index": { "_id": }}
{ "productID" : "XHDK-A-1293-#fJ3","desc":"iPhone" }
{ "index": { "_id": }}
{ "productID" : "KDKE-B-9947-#kL5","desc":"iPad" }
{ "index": { "_id": }}
{ "productID" : "JODL-X-1937-#pV7","desc":"MBP" }
POST _analyze
{
"text":"iPhone"
} GET /products/products/_search
{
"query": {
"term": {
"desc.keyword": {
"value": "iPhone"
}
}
}
}
GET /products/products/_search
{
"explain": true,
"query": {
"constant_score": {
"filter": {
"term": {
"desc.keyword": "iPhone"
}
} }
}
} PUT /website
{
"mappings": {
"article": {
"properties": {
"title": {
"type": "text",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
},
"fielddata": true
},
"content": {
"type": "text"
},
"post_date": {
"type": "date"
},
"author_id": {
"type": "long"
}
}
}
}
} PUT /blogs/blogs/
{
"title": "Quick brown rabbits",
"body": "Brown rabbits are commonly see."
} PUT /blogs/blogs/
{
"title": "Keeping pets healthy",
"body": "My quick brown fox eats rabbits on a regular basis."
} POST /blogs/blogs/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"title": "Brown fox"
}
},
{
"match": {
"body": "Brown fox"
}
}
]
}
}
} GET /blogs/blogs/_search
{
"query": {
"dis_max": {
"tie_breaker": 0.7,
"boost": 1.2,
"queries": [
{
"match": {
"title": "Brown fox"
}
},
{
"match": {
"body": "Brown fox"
}
}
]
}
}
}
POST blogs/blogs/_search
{
"query": {
"dis_max": {
"queries": [
{ "match": { "title": "Quick pets" }},
{ "match": { "body": "Quick pets" }}
],
"tie_breaker": 0.2
}
}
}
GET articles/_search
DELETE articles PUT articles
{
"mappings": {
"articles"{
"properties": {
"title_completion":{
"type": "completion"
}
}
}
}
} PUT /articles
{
"mappings": {
"articles": {
"properties": {
"title_completion":{
"type": "completion"
}
}
}
}
} POST articles/articles/_bulk
{ "index" : { } }
{ "title_completion": "lucene is very cool"}
{ "index" : { } }
{ "title_completion": "Elasticsearch builds on top of lucene"}
{ "index" : { } }
{ "title_completion": "Elasticsearch rocks"}
{ "index" : { } }
{ "title_completion": "elastic is the company behind ELK stack"}
{ "index" : { } }
{ "title_completion": "Elk stack rocks"}
{ "index" : {} } POST articles/_search?pretty
{
"size": ,
"suggest": {
"article-suggester": {
"prefix": "e ",
"completion": {
"field": "title_completion"
}
}
}
}
GET articles/articles/_search
{
"explain": true,
"suggest":{
"articles-suggest":{
"prefix":"elk",
"completion":{
"field":"title_completion"
}
}
}
} PUT /articles
{
"mappings": {
"articles": {
"properties": {
"title_completion":{
"type": "completion"
}
}
}
}
}
DELETE comments
PUT comments
PUT comments/_mapping PUT comments
{
"mappings": {
"comments":{
"properties": {
"comment_autocomplete":{
"type": "completion",
"contexts":[{
"type":"category",
"name":"comment_category"
}]
}
}
}
}
}
DELETE comments GET comments/_search PUT comments
{
"mappings": {
"comments": {
"properties": {
"comment_autocomplete": {
"type": "completion",
"contexts": [
{
"type": "category",
"name": "comment_category"
}
]
}
}
}
}
} POST comments/comments/
{
"comment":"I love the star war movies",
"comment_autocomplete":{
"input":["star wars"],
"contexts":{
"comment_category":"movies"
}
}
}
POST comments/comments/
{
"comment":"Where can I find a Starbucks",
"comment_autocomplete":{
"input":["starbucks"],
"contexts":{
"comment_category":"coffee"
}
}
}
GET comments/_search
{
"size": ,
"suggest": {
"my_suggest": {
"prefix": "sta",
"completion":{
"field":"comment_autocomplete",
"contexts":{
"comment_category":"movies"
}
}
}
}
} GET comments/_search
{
"size": ,
"suggest": {
"my_suggest": {
"prefix": "sta",
"completion":{
"field":"comment_autocomplete",
"contexts":{
"comment_category":"coffee"
}
}
}
}
} PUT _snapshot/my_hdfs_repository/snapshot_4
{
"indices": "my_index",
"ignore_unavailable": true,
"include_global_state": false,
"partial": true
} GET /_cat/health?v GET _cluster/health GET /_cat/indices?v GET /_cat/nodes?v POST /car/transactions/_bulk
{ "index": {}}
{ "price" : , "color" : "red", "make" : "honda", "sold" : "2014-10-28" }
{ "index": {}}
{ "price" : , "color" : "red", "make" : "honda", "sold" : "2014-11-05" }
{ "index": {}}
{ "price" : , "color" : "green", "make" : "ford", "sold" : "2014-05-18" }
{ "index": {}}
{ "price" : , "color" : "blue", "make" : "toyota", "sold" : "2014-07-02" }
{ "index": {}}
{ "price" : , "color" : "green", "make" : "toyota", "sold" : "2014-08-19" }
{ "index": {}}
{ "price" : , "color" : "red", "make" : "honda", "sold" : "2014-11-05" }
{ "index": {}}
{ "price" : , "color" : "red", "make" : "bmw", "sold" : "2014-01-01" }
{ "index": {}}
{ "price" : , "color" : "blue", "make" : "ford", "sold" : "2014-02-12" } #an'yan'se'fen'zu安颜色分组 GET /car/transactions/_search
{
"size": ,
"aggs": {
"group_by_color": {
"terms": {
"field": "color.keyword"
}
}
}
} #先按颜色分组后计算平均价格 #select color, count(color) as cnt, avg(price) as avg_price from cars group by color order by cnt desc;
GET /car/transactions/_search
{
"size": ,
"aggs": {
"group_by_color": {
"terms": {
"field": "color.keyword"
},
"aggs": {
"avg_color": {
"avg": {
"field": "price"
}
}
}
} }
} #统计每种颜色汽车制造商的分布dsl实现 #select color, make from cars order by color;
GET /car/transactions/_search
{
"size": ,
"aggs": {
"group_by_color": {
"terms": {
"field": "color.keyword"
},
"aggs": {
"group_by_make": {
"terms": {
"field": "make.keyword"
}
}
}
}
}
} GET _stats/fielddata?human&fields=my_join_field GET _nodes/stats/indices/fielddata?human&fields=my_join_field #统计每个制造商的最低、最高价格 #select make, min(price) as min_price, max(price) as max_price from cars group by make; GET /car/transactions/_search
{
"size": ,
"aggs": {
"group_by_make": {
"terms": {
"field": "make.keyword"
},
"aggs": {
"min_price":{
"min": {
"field": "price"
}
},
"max_price":{
"max": {
"field": "price"
}
}
}
}
}
}
#select *, avg(price) from cars where period_diff(date_format(now() , '%Y%m') , date_format(sold, '%Y%m')) >
#and make = "ford";
GET /car/transactions/_search
{
"size": ,
"aggs": {
"group_by_price": {
"histogram": {
"field": "price",
"interval":
},
"aggs": {
"revenue": {
"sum": {
"field": "price"
}
}
}
}
}
}
GET /car/transactions/_search GET /car/transactions/_search
{
"size": ,
"aggs": {
"group_by_data":{
"date_histogram": {
"field": "sold",
"interval": "month",
"format": "yyyy-MM-dd"
}
}
}
} GET /car/transactions/_search
{
"size": ,
"aggs": {
"sales": {
"date_histogram": {
"field": "sold",
"interval": "month",
"format": "yyyy-MM-dd",
"min_doc_count": ,
"extended_bounds": {
"min": "2014-01-01",
"max": "2014-12-31"
}
}
}
}
} GET /car/transactions/_search
{
"size": ,
"query": {
"match": {
"make.keyword": "ford"
}
},
"aggs": {
"colors": {
"terms": {
"field": "color.keyword"
}
}
}
} GET /car/transactions/_search
{
"size": ,
"query": {
"match": {
"make.keyword": "ford"
}
},
"aggs": {
"single_avg_price": {
"avg": {
"field": "price"
}
},
"all": {
"global": {},
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
} GET /car/transactions/_search
{
"query": {
"match": {
"make": "ford"
}
},
"aggs":{
"aggs_global":{
"filter":{
"range": {
"price": {
"gte": ,
"lte":
}
}
},
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
} GET /car/transactions/_search
{
"query": {
"match": {
"make": "ford"
}
},
"post_filter": {
"term": {
"color.keyword": "green"
}
},
"aggs": {
"group_by_price": {
"terms": {
"field": "color.keyword"
}
}
}
} #post_filter 会过滤搜索结果,只展示绿色 ford 汽车。这在查询执行过 后 发生,所以聚合不受影响。 GET /car/transactions/_search
{
"size": ,
"aggs": {
"group_by_color":{
"terms": {
"field": "color.keyword",
"order": {
"_term": "asc"
}
}
}
}
} GET /car/transactions/_search
{
"size": ,
"aggs": {
"colors": {
"terms": {
"field": "color.keyword",
"order": {
"_count": "asc"
}
}
}
}
} #按照 汽车颜色分组,再求平均价格,价格升序 GET /car/transactions/_search
{
"size": ,
"aggs": {
"group_by_colors": {
"terms": {
"field": "color.keyword",
"order": {
"_term": "asc"
}
},
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
GET /car/transactions/_search
{
"size": ,
"aggs": {
"distinct_colors":{
"cardinality": {
"field": "color.keyword"
}
}
}
} GET _nodes/hot_threads GET /_cat/thread_pool?v #HDFS 数据恢复
PUT _snapshot/my_hdfs_repository/snapshot_6
{
"indices": "my_index",
"ignore_unavailable": true,
"include_global_state": false,
"partial": true
} DELETE my_index GET my_index/_search POST /_snapshot/my_hdfs_repository/snapshot_6/_restore?pretty GET my_index/_search GET /_snapshot/my_hdfs_repository
elasticsearch 搜索提示DSL的更多相关文章
- Elasticsearch(ES)的高级搜索(DSL搜索)(上篇)
1. 概述 之前聊了一下 Elasticsearch(ES)的基本使用,今天我们聊聊 Elasticsearch(ES)的高级搜索(DSL搜索),由于DSL搜索内容比较多,因此分为两篇文章完成. 2. ...
- Elasticsearch(ES)的高级搜索(DSL搜索)(下篇)
1. 概述 之前聊了Elasticsearch(ES)的高级搜索(DSL搜索)的一部分内容,今天把剩下的部分聊完. 2. 场景说明 2.1 创建索引同时创建映射 PUT http://192.168 ...
- ElasticStack学习(六):ElasticSearch搜索初探
一.ElasticSearch搜索介绍 1.ElasticSearch搜索方式主要分为以下两种: 1).URI Search:此种查询主要是使用Http的Get方法,在URL中使用查询参数进行查询: ...
- 利用kibana学习 elasticsearch restful api (DSL)
利用kibana学习 elasticsearch restful api (DSL) 1.了解elasticsearch基本概念Index: databaseType: tableDocument: ...
- Elasticsearch 搜索API
章节 Elasticsearch 基本概念 Elasticsearch 安装 Elasticsearch 使用集群 Elasticsearch 健康检查 Elasticsearch 列出索引 Elas ...
- Elasticsearch 搜索数据
章节 Elasticsearch 基本概念 Elasticsearch 安装 Elasticsearch 使用集群 Elasticsearch 健康检查 Elasticsearch 列出索引 Elas ...
- Elasticsearch搜索资料汇总
Elasticsearch 简介 Elasticsearch(ES)是一个基于Lucene 构建的开源分布式搜索分析引擎,可以近实时的索引.检索数据.具备高可靠.易使用.社区活跃等特点,在全文检索.日 ...
- 看完这篇还不会 Elasticsearch 搜索,那我就哭了!
本文主要介绍 ElasticSearch 搜索相关的知识,首先会介绍下 URI Search 和 Request Body Search,同时也会学习什么是搜索的相关性,如何衡量相关性. Search ...
- C# WinForm 技巧:COMBOBOX搜索提示
comboBox和textBox支持内置的搜索提示功能, 在form的InitializeComponent()中添加如下语句: this.comboBox1.AutoCompleteCustom ...
随机推荐
- Redis的入门
什么是NOSQL? NOSQL(Not Only SQL)不仅仅是数据库,是一种全新的理念,泛指非关系型的数据库. 为什么需要NOSQL? 随着互联网的高速崛起,网站的用户群的增加,访问量的上升,传统 ...
- 【转载】TCP协议
首部格式 图释: 各个段位说明: 源端口和目的端口:各占 2 字节.端口是传输层与应用层的服务接口.传输层的复用和分用功能都要通过端口才能实现 序号:占 4 字节.TCP 连接中传送的数据流中的每一个 ...
- day008-python内置函数
一.ptthon内置函数 二.内置函数详细概述 2.1 abs(x):函数返回数字的绝对值. 注意: 1)x -- 数值表达式,可以是整数,浮点数,复数. 2)如果参数是一个复数,则返回它的大小. ...
- 验证码破解 | Selenium模拟登陆12306
12306官网登录的验证码破解比较简单,验证码是常规的点触类型验证码,使用超级鹰识别率比较高. 思路: (1)webdriver打开浏览器: (2)先对整个屏幕截屏,通过标签定位找到验证码图片,并定位 ...
- [RN] React Native Fetch请求设置超时
一.实现思路 根据Promise.race的特性,我们在Promise.race里面添加两个任务,一个是正常的网络请求任务A,另外一个便是网络延时任务B,网络延时可以利用setTimeout方法实现. ...
- 2019 NOIP 夏令营(模拟赛1)
一来到夏令营,第一天上机就考试, 哎,简直不让人活了 这难道是给我们的见面礼??? A https://www.luogu.org/problemnew/show/P1197 #include< ...
- HDU 4828 小明系列故事——捉迷藏
漂亮妹子点击就送:http://acm.hdu.edu.cn/showproblem.php?pid=4528 Time Limit: 500/200 MS (Java/Others) Memo ...
- k8s实现灰度发布
灰度发布在实际生产部署中是经常被使用的方式,常规的方法是手动从前端LB(负载均衡)上将后端服务器摘掉,然后,停服务,最后上传代码,完成软连接更新.在使用CI/CD工具时,这个过程变得自动化了,我们只需 ...
- Java重启后不能打开的一些解决方法
点开环境变量设置,重新确定一下(据说是win10的原因) 将环境变量中path与CLASSPATH中的%JAVA_HOME%改为JAVA_HOME的值.参考https://blog.csdn.net/ ...
- [Gamma阶段]第五次Scrum Meeting
Scrum Meeting博客目录 [Gamma阶段]第五次Scrum Meeting 基本信息 名称 时间 地点 时长 第五次Scrum Meeting 19/05/31 大运村寝室6楼 30min ...