es-DSL-检索相关

方便做测试,在es-head上比较方便,毕竟json难写........

1、多字段/全文检索

{  
    "query": {
         "multi_match": {
              "query": "xxxx""fields" : ["field1","field2"]
        }
   }
}

fields:指定要检索的字段,去掉fields,表示不限定字段

2、分页+match检索

{
  "query": {
    "match": {
       "name": "kobe"
    }
  },
  "size": 20,
  "from": 0,
  "_source": ["name", "team", "score"],
  "highlight": {
    "fields": {
       "name": {}
    }
  }
}

3、bool查询

bool-must/must_not/should

4、通配符查询

{
  "query": {
    "wildcard": {
      "name": {
        "value": "ko*"
      }
    }
  },
  "_source": ["name", "team"]
 }

5、匹配短语查询

{
  "query": {
    "multi_match": {
      "query": "search engine",
      "fields": ["title", "summary"],
      "type": "phrase",
      "slop": 3
    }
  },
  "_source": [ "title", "summary", "publish_date" ]
}

6、range

{
  "query": {
    "range": {
      "create_time": {
        "gte": "2015-01-01",
        "lte": "2015-12-31"
      }
    }
  }
}

 7、filter(无评分,快)

{
  "query": {
    "bool": {
      "filter": {
          "term": {
          "name": "张三"
        }
      }
    }
  }
}

 8、query_string(高级查询,需要理解查询语法,书写的门槛有点高,es会先对query里的内容进行分析,最终生成一个综合的查询条件)

{
  "query": {
    "query_string": {
      "query": "(content:this OR name:this) AND (content:that OR name:that)"
    }
  }
}

 9、term(简单的单个词条查询)

{
  "query": {
    "term": {
      "human_id": {
         "value": "22"
      }
    }
  }
}

10、terms(简单的单字段的多值查询)

{
  "query": {
    "terms": {
      "human_id": ["11","22"]
    }
  }
}

 

posted @ 2021-04-01 15:02  鼠标的博客  阅读(110)  评论(0编辑  收藏  举报