1.复合查询
地址:http://10.0.0.109:9200/nhip-info-20230628/_search/
post
{ "size": 20, "query": { "bool": { "must": [ { "match_all": { "boost": 1.0 } }, { "match": { "logType": { "query": "sendreceiver", "operator": "OR", "prefix_length": 0, "max_expansions": 50, "fuzzy_transpositions": true, "lenient": false, "zero_terms_query": "NONE", "auto_generate_synonyms_phrase_query": true, "boost": 1.0 } } }, { "term": { "user.keyword": { "value": "QT-ZZJ", "boost": 1.0 } } }, { "range": { "businessTime": { "from": "2023-06-28 00:00:00", "to": "2023-06-28 23:59:59", "include_lower": true, "include_upper": true, "format": "yyyy-MM-dd HH:mm:ss", "boost": 1.0 } } } ], "adjust_pure_negative": true, "boost": 1.0 } }, "sort": [{ "businessTime": { "order": "desc" } }] }
2.查询脚本说明
{ "query": { "bool": { "must": [ //精确匹配HIS字段 {"term": {"domain.keyword": "HIS"}}, //通配符匹配带有0002字段 *代表一个或多个字符 ? 仅代表一个字符 注意:这个查询功能影响性能 {"wildcard": {"localTransId.keyword": "*0002*"}} ], "filter": [ //filter 类似于 SQL 里面的where 语句,同时 filter 可以将查询缓存到内存当中,这样可以大大加大下一次的查询速度 推荐使用filter //[]可以匹配多个值 {"term": {"tag": ["tech","01"]}} ], "must_not": [ //范围查询 gt: > lt: < {"range": {"age": {"gt": "1","lt": "10"}}}, //范围查询 gte: >= lte: <= {"range": {"time": {"gte": "1","lte": "10"}}} ], "should": [ //前缀查询wow {"prefix": {"tag": "wow"}}, {"term": {"tag": "elasticsearch"}} ], //该参数控制一个文档必须匹配的should子查询的数量,默认0 "minimum_should_match": 1 } }, //从哪个结果开始返回 "from": 0, //定义返回最大的结果数 "size": 10, //根据price字段排序 desc 降序 asc 升序 "sort": [{"price":{ "order":"desc"}}], "aggs": {} }
3.match里一些模糊查找
4.term精确查找,有些类型是keyword,写法如下:
如果不确定,可以在这里生成脚本参考:
标签:term,1.0,boost,查询,query,true,ES From: https://www.cnblogs.com/wwzd/p/17524316.html