{
"mappings": {
"novel": {
"properties": {
"word_count": {
"type": "interger"
},
"author": {
"type": "keyword"
},
"title": {
"type": "text"
},
"publish_date": {
"format": "yyyy-MM-dd HH:mm:ss||yyy-MM-dd||epoch_mills",
"type": "date"
}
}
}
}
}
form指定从哪里返回
size指定返回数量
{
"query": {
"match_all": {}
}
"from": 1
"size": 1
}
{
"query": {
"match": {
"title": "joker"
},
"sort": [
{"publish_date":{"order":"desc}}
]
}
}
{
"aggs": {
"group_by_word_count": {
"terms": {
"field": "word_count"
}
},
"group_by_publish_date": {
"term": {
"field": "publish_date"
}
}
}
}
{
"aggs": {
"grades_word_count": {
"stats": {
"field": "word_count"
}
}
}
}
特定字段查询所指特定值
会根据匹配程度生成不同的匹配分数
{
"query": {
"match": {
"title": "ElasticSearch入门"
}
}
}
{
"query": {
"match_phrase": {
"title": "ElasticSearch入门"
}
}
}
{
"query": {
"multi_match": {
"query": "joker"
"fields": ["author", "title"]
}
}
}
{
"query": {
"query_string": {
"query": "(ElasticSearch AND 大法) OR Python",
"fields": ["title", "author"]
}
}
}
{
"query": {
"term": {
"word_count": 1000
}
}
}
{
"query": {
"range": {
"word_count": {
"gte": 1000,
"lg": 2000
}
}
}
}
{
"query": {
"range": {
"publish_date": {
"gte": "2018-1-1",
"lg": "now"
}
}
}
}
只判断该文档是否满足条件,只有是或者不是
而且Filter的结果会加入缓存,比Query快一些
{
"query": {
"bool": {
"filter": {
"term": {
"word_count": 1000
}
}
}
}
}
以一定的逻辑组合子条件查询
{
"query": {
"constant_score": {
"filter": {
"match": {
"title": "ElasticSearch"
}
}
},
"boost": 2
}
}
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "joker"
},
"match": {
"title": "ElasticSearch"
}
}
],
"filter": [
"term": {
"word_count": 1000
}
]
}
}
}