elasticsearch

mac2022-06-30  34

 

https://www.elastic.co/

https://www.elastic.co/cn/downloads

--head插件的使用

https://github.com/ ==>  

mobz/elasticsearch-head

 

 

--分布式安装

--基础概念

 

{ "settings": { "number_of_shards": 3, "number_of_replicas": 1 }, "mappings": { "man": { "properties": { "name": { "type": "text" }, "country": { "type": "keyword" }, "age": { "type": "integer" }, "date": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss|| yyyy-MM-dd||epoch_millis" } } }, "woman": { } } }

 

put

ip:端口/索引/类型/id

{ "name": "tom", "country": "US", "age": 30, "date": "1987-05-05" }

注: post方式, 自动生成id, 无序指定id值

post

ip:端口/索引/类型/id/_update

{ "doc": { "name": "haah" } } { "script": { "lang": "painless", "inline": "ctx._source.age += 10" } } { "script": { "lang": "painless", "inline": "ctx._source.age = parmas.age", "parmas": { "age": 100 } } }

注: delete方式

--基本查询

{ "settings": { "number_of_shards": 3, "number_of_replicas": 1 }, "mappings": { "novel": { "properties": { "word_count": { "type": "integer" }, "author": { "type": "keyword" }, "title": { "type": "text" }, "publish_date": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss|| yyyy-MM-dd||epoch_millis" } } } } }

get:

post: ip:端口/索引/类型/_search

{ "query": { "match_all": {} } } { "query": { "match_all": {} }, "from": 1, "size": 2 } { "query": { "match_all": { "title": "ElasticSearch" } }, "sort": [ {"publish_date": {"order": "desc"}} ] } { "aggs": { "group_by_word_count": { "terms": { "field": "word_count" } } } } { "aggs": { "group_by_word_count": { "terms": { "field": "word_count" } }, "group_by_publish_date": { "terms": { "field": "publish_date" } } } } { "aggs": { "group_by_word_count": { "stats": { "field": "word_count" } } } } { "aggs": { "group_by_word_count": { "min": { "field": "word_count" } } } }

--高级查询

1全文本

 

模糊匹配{ "query": { "match": { "title": "ElasticSearch入门" } } } 整个{ "query": { "match_phrase": { "title": "ElasticSearch入门" } } } 多字段 { "query": { "multi_match": { "query": "haah", "fields": ["author", "title"] } } } 语法查询{ "query": { "query_string": { "query": "ElasticSearch AND 大发", } } } { "query": { "query_string": { "query": "(ElasticSearch AND 大发) OR Pythonh", } } } { "query": { "query_string": { "query": "ElasticSearch OR haha", "fields": ["title", "author"] } } }

2字段查询(结构化的查询)

{ "query": { "term": { "word_count": 1000 } } } { "query": { "term": { "author": "haha" } } } 范围{ "query": { "range": { "word_count": { "gte": 1000, "lte": 2000 } } } } { "query": { "range": { "publish_date": { "gt": "2017-01-01", "lte": "2017-12-31" } } } } { "query": { "range": { "publish_date": { "gt": "2017-01-01", "lte": "now" } } } }

{ "query": { "bool": { "filter": { "term": { "word_count": 1000 } } } } }

 

1固定分数查询

{ "query": { "constant_score": { "filter": { "match": { "title": "ElasticSearch入门" } } } } } { "query": { "constant_score": { "filter": { "match": { "title": "ElasticSearch入门" } }, "boost": 2 } } }

2布尔查询

{ "query": { "bool": { "should": [ { "match": { "author": "haha" } }, { "match": { "title": "ElasticSearch" } } ] } } } { "query": { "bool": { "must": [ { "match": { "author": "haha" } }, { "match": { "title": "ElasticSearch" } } ] } } } { "query": { "bool": { "must": [ { "match": { "author": "haha" } }, { "match": { "title": "ElasticSearch" } } ] }, "filter": [ { "term": { "word_count": 1000 } } ] } } { "query": { "bool": { "must_not": { "term": { "author": "haah" } } } } }

spring boot 集成 es

 

转载于:https://www.cnblogs.com/liuzhipeng/p/7565412.html

最新回复(0)