es:http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/query-dsl-intro.html
下一页:
内容
查询DSL是弹性的搜索语言,使用JSON接口。
使得我们的查询更具有弹性,更具体,易读。
GET /_search
{
"query": YOUR_QUERY_HERE
}
空搜索类似于下面的:
GET /_search
{
"query": {
"match_all": {}
}
}
一个查询的结构:
{
QUERY_NAME: {
ARGUMENT: VALUE,
ARGUMENT: VALUE,...
}
}
或者如下:
{
QUERY_NAME: {
FIELD_NAME: {
ARGUMENT: VALUE,
ARGUMENT: VALUE,...
}
}
}
比如,查找tweet字段包含elasticsearch:
{
"match": {
"tweet": "elasticsearch"
}
}
完整的如下:
GET /_search
{
"query": {
"match": {
"tweet": "elasticsearch"
}
}
}
更复杂的如下:
{
"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
}
}
不用担心细节,我们后面会解释。