ES查询相关

    技术2022-07-14  65

    ES查询

    匹配查询
    GET /yitu_result/_search?size=1000 { "query": { "match": { "date":"2020070108" } } }
    结果过滤
    GET /yitu_result/_search { "query": { "match": { "date":"2020070108" } }, "_source": ["face_image"] }
    结果排序

    #聚合查询报错 Fielddata is disabled on text fields by default. Set fielddata=true on [title] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.

    开启加载fielddata
    PUT yitu_result/_mapping { "properties": { "date": { "type": "text", "fielddata": true } } }
    排序查询
    GET /yitu_result/_search { "query": { "match": { "date":"2020070108" } }, "sort": [ { "date": { "order": "desc" } } ] }
    分页查询
    GET /yitu_result/_search { "query": { "match": { "channel_floor": "06" } }, "sort": [ { "date": { "order": "desc" } } ], "from": 0, # 从第几页开始 "size": 1 # 查询多少条数据 }
    布尔值查询
    must(所有条件都要符合)
    GET yitu_result/_doc/_search { "query":{ "bool":{ "must":[ { "match":{ "date":"2020070109" } }, { "match":{ "channel_name":"06153" } } ] } } }
    should (or),有一个匹配就行
    GET yitu_result/_doc/_search { "query":{ "bool":{ "should":[ { "match":{ "date":"2020070109" } }, { "match":{ "date":"2020070108" } } ] } } }
    must_not 不必须,就是查询除这个以外的所有
    GET yitu_result/_doc/_search { "query":{ "bool":{ "must_not":[ { "match":{ "channel_name":"06153" } } ] } } }
    过滤器filter
    gt 大于lt 小于gte 大于等于lte 小于等于 GET yitu_result/_doc/_search { "query":{ "bool":{ "must":[ { "match":{ "channel_name":"06161" } } ], "filter":{ "range":{ # 有多个层级就一直点 "retrieval_results.similar_faces.similarity":{ "gte":80 } } } } } }

    多条件匹配查询

    GET /yitu_result/_search { "query": { "match": { "date": "2020070114 2020070111" } } }
    精确查询

    term查询是直接通过倒排索引指定的词条进行精确查询

    关于分词:

    term,直接查询精确的

    match,会使用分词器解析(先分析文档,然后再通过分析的文档进行查询)

    两个类型 text keyword

    多个值匹配精确查询

    高亮查询

    GET /yitu_result/_search { "query": { "match": { "date": "2020070114" } }, "highlight": { #自定义高亮格式 "pre_tags": "<p class='key' style='color:red'>", "post_tags": "</p>", "fields": { "date": {} } } }

    集成SpringBoot

    Processed: 0.012, SQL: 9