http://localhost:9200/
{
"settings":{
"number_of_shards":3,
"number_of_replicas":1
},
"mappings":{
"novel":{
"properties":{
"word_count":{
"type":"integer"
},
"author":{
"type":"keyword"
},
"title":{
"type":"text"
},
"public_date":{
"type":"date",
"format":"yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
}
}
}
}
}
http://localhost:9200/book/novel/_mappings
{
"novel": {
"properties": {
"word_count": {
"type": "integer"
},
"author": {
"type": "keyword"
},
"title": {
"type": "text"
},
"public_date": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
}
}
}
}
http://localhost:9200/people/man/1
{
"name":"张枋",
"country":"China",
"age":26,
"date":"1992-01-28"
}
http://localhost:9200/people/man/1
{
"script":{
"lang":"painless",
"inline":"ctx._source.age=params.age",
"params":{
"age":100
}
}
}
query:(会计算匹配程度score,而filter只判断文档是否满足条件)
http://localhost:9200/book/novel/5
post http://localhost:9200/book/_search
{
"query":{
"match_all":{}
},
"from":1,
"size":1
}
{
"query": {
"match": {
"title": "雪"
}
},
"sort": [
{
"public_date": {
"order": "desc"
}
}
]
}
{
"query": {
"match": {
"title": "雪"
}
},
"sort": [
{
"public_date": {
"order": "desc"
}
}
],
"from": 1,
"size": 1
}
聚合查询
{
"aggs": {
"group_by_word_count": {
"terms": {
"field": "word_count"
}
},
"group_by_public_date": {
"terms": {
"field": "public_date"
}
},
"grades_word_count": {
"stats": {
"field": "word_count"
}
},
"grades_word_count_min": {
"min": {
"field": "word_count"
}
}
}
}
非结构化查询
{
"query":{
"match_phrase":{
"title":"雪"
}
}
}
{
"query": {
"multi_match": {
"query": "雪人",
"fields": [
"author",
"title"
]
}
}
}
{
"query": {
"query_string": {
"query": "(雪 AND 人) OR 园"
}
}
}
{
"query": {
"query_string": {
"query": "雪 OR 人",
"fields": [
"title",
"author"
]
}
}
}
字段查询(结构化)
{
"query": {
"term": {
"author": "鲁迅"
}
}
}
{
"query": {
"range": {
"word_count": {
"gte":100,//gt e:equals
"lte":1000//lt
}
}
}
}
filter:(需要结合bool使用,查询结果通过true|false过滤,查询速度快于query)
{
"query":{
"bool":{
"filter":{
"term":{
"word_count":500
}
}
}
}
}
{
"query": {
"bool": {
"should": [
{
"match": {
"author": "毛泽东"
}
},
{
"match": {
"title": "雪"
}
}
],
"filter":[
{
"term":{
"word_count":500
}
}
]
}
}
}
{
"query": {
"bool": {
"must": [
{
"match": {
"author": "毛泽东"
}
},
{
"match": {
"title": "雪"
}
}
]
}
}
}
全文搜索:
http://localhost:9200/_search
{
"query":{
"match":{
"title":"雪"
}
}
}
固定分数查询
{
"query": {
"constant_score": {
"filter": {
"match": {
"author": "毛泽东"
}
},
"boost": 2
}
}
}
spring集成es:
https://www.cnblogs.com/ouyanxia/p/8288749.html