es中bool复合查询和match_phrase精确匹配性能对比

第一种是bool复合查询must:如果有多个条件,这些条件都必须满足 and与,性能的话如下图

# -*- coding: utf-8 -*-
import time
from connecting import es

start_time = time.time()
search_query = {
  "query": {
    "bool": {
      "must":[
{"match":{
    "domain":"torum43tajnrxritn4iumy75giwb5yfw6cjq2czjikhtcac67tfif2yd.onion"}},
{"match":{
    "topic_id":"3911"}}
  ]
    }
  }
}
r = es.search(index='topic', doc_type='_doc', body=search_query, timeout='50m')
res_lst = r["hits"]["hits"]
for rec in res_lst:
    print(rec["_source"]["url"])
    end_time = time.time()
    print(end_time - start_time)

es中bool复合查询和match_phrase精确匹配性能对比_第1张图片
第二种match_phrase精确匹配,xxxx是你查询的关键词但也会匹配到xxxxyyyy这种,性能如下图

# -*- coding: utf-8 -*-
import time
from connecting import es


start_time = time.time()
search_query = {
    "query": {
        "match_phrase": {
            "topic_id": {
                "query": '3911'
            }
        }
    }
}
r = es.search(index='topic', doc_type='_doc', body=search_query, timeout='50m')
res_lst = r["hits"]["hits"]
for rec in res_lst:
    print(rec["_source"]["url"])
    end_time = time.time()
    print(end_time - start_time)

es中bool复合查询和match_phrase精确匹配性能对比_第2张图片
显然bool复合查询多指定了个条件后性能是优于match_phrase的精确匹配的,两种查询方式都有特定的应用场合具体还要看应用场景

你可能感兴趣的:(Elasticsearch)