ES学习之DSL-2

1.Match多字段查询,同时对多个字段进行查询

get /index1/_search
{
  "query":{
    "multi_match": {
      "query": "20",
      "fields": ["name","age"]
    }
  }
}

2.对查询字符串不进行分词,使用term

et /index1/_search
{
  "query":{
    "term": {
      "name": {
        "value": "jack"
      }
    }
  }
}

3.批量进行term查询,使用terms

get /index1/_search
{
  "query":{
   "terms": {
     "name": [
       "jack",
       "chen",
       "1"
     ]
   }
  }
}

4.使用range对数字或时间进行范围查询

get /index1/_search
{
  "query":
  {
    "range": {
      "age": {
        "gte": 10,
        "lte": 20
      }
    }
  }
}

5.不计算相关性得分的查询,会缓存结果,性能高的查询

get /index1/_search
{
  "query":
  {
    "bool": {
      "filter": [
        {
          "term": {
            "name": "jack"
          }
        }
      ]
    }
  }
}

6.计算相关性得分,必须满足条件使用must

GET /index1/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "name": "jack"
          }
        },
        {
          "match": {
            "age": "10"
          }
        }
      ]
    }
  }
}

7.复合查询使用should时需注意,如果只有should条件,那么至少要满足一个should,如果should和must同时使用,那么should可满足也可不满足,满足会影响加分