elasticsearch-5. 查询语言

2018-04-30  本文已影响0人  donglq

查询语言

GET /bank/_search
{
  "query": { "match_all": {} },
  "from": 10,
  "size": 10,
  "sort": { "balance": { "order": "desc" } },
  "_source": ["account_number", "balance"]
}
GET /bank/_search
{
  "query": { "match": { "account_number": 20 } }
}
  1. 返回所有address字段中包含mill的文档
GET /bank/_search
{
  "query": { "match": { "address": "mill" } }
}
  1. 返回所有address字段中包含mill或lane的文档
GET /bank/_search
{
  "query": { "match": { "address": "mill lane" } }
}
  1. 返回所有address字段中包含mill lane语句的文档
GET /bank/_search
{
  "query": { "match_phrase": { "address": "mill lane" } }
}
  1. bool查询,使用布尔逻辑将小的查询构成大的查询
GET /bank/_search
{
  "query": {
    "bool": {
      "must": [
        { "match": { "address": "mill" } },
        { "match": { "address": "lane" } }
      ]
    }
  }
}

此例子由两个match查询构成,返回address字段中包含mill和lane的文档

GET /bank/_search
{
  "query": {
    "bool": {
      "should": [
        { "match": { "address": "mill" } },
        { "match": { "address": "lane" } }
      ]
    }
  }
}

返回address字段中包含mill或lane的文档

GET /bank/_search
{
  "query": {
    "bool": {
      "must_not": [
        { "match": { "address": "mill" } },
        { "match": { "address": "lane" } }
      ]
    }
  }
}

此例子由两个match查询构成,返回address字段中不包含mill和lane的文档

GET /bank/_search
{
  "query": {
    "bool": {
      "must": [
        { "match": { "age": "40" } }
      ],
      "must_not": [
        { "match": { "state": "ID" } }
      ]
    }
  }
}

返回 age = 40 同时 state != ID 的文档

上一篇 下一篇

猜你喜欢

热点阅读