GET /index_2014*/type1,type2/_search {}
GET /_search { "from": 30, "size": 10 } 结构化查询 Query DSL
{ "bool": { "must": { "match": { "tweet": "elasticsearch" }}, "must_not": { "match": { "name": "mary" }}, "should": { "match": { "tweet": "full text" }} } }
{ "bool": { "must": { "match": { "email": "business opportunity" }}, "should": [ { "match": { "starred": true }}, { "bool": { "must": { "folder": "inbox" }}, "must_not": { "spam": true }} }} ], "minimum_should_match": 1 } } 查询与过滤
{ "term": { "age": 26 }} { "term": { "date": "2014-09-01" }} { "term": { "public": true }} { "term": { "tag": "full_text" }}
{ "terms": { "tag": [ "search", "full_text", "nosql" ] } }
{ "range": { "age": { "gte": 20, "lt": 30 } } } 范围操作符包含: gt :: 大于 gte:: 大于等于 lt :: 小于 lte:: 小于等于
{ "exists": { "field": "title" } }
{ "bool": { "must": { "term": { "folder": "inbox" }}, "must_not": { "term": { "tag": "spam" }}, "should": [ { "term": { "starred": true }}, { "term": { "unread": true }} ] } }
{ "match_all": {} }
{ "match": { "tweet": "About Search" } }
{ "multi_match": { "query": "full text search", "fields": [ "title", "body" ] } }
must:: 查询指定文档一定要被包含。 must_not:: 查询指定文档一定不要被包含。 should:: 查询指定文档,有则可以为文档相关性加分。
{ "bool": { "must": { "match": { "title": "how to make millions" }}, "must_not": { "match": { "tag": "spam" }}, "should": [ { "match": { "tag": "starred" }}, { "range": { "date": { "gte": "2014-01-01" }}} ] } } 查询与过滤条件的合并
{ "filtered": { "query": { "match": { "email": "business opportunity" }}, "filter": { "term": { "folder": "inbox" }} } }
GET /_search { "query": { "filtered": { "query": { "match": { "email": "business opportunity" }}, "filter": { "term": { "folder": "inbox" }} } } }
GET /ecommerce/product/_validate/query?explain { "query": { "filtered":{ "query":{ "match":{ "name":"jiajieshi yagao" } }, "filter":{ "term":{ "price":40 } } } } }
结果
{ "valid": false, "error": "org.elasticsearch.common.ParsingException: no [query] registered for [filtered]" }