a" plain"之间的区别术语查询和使用过滤器的术语查询

时间:2015-01-30 11:34:25

标签: elasticsearch

我试图了解它们之间的区别:

  • 一个“普通”弹性搜索查询,该查询将匹配条款查询并返回一定数量的匹配。
  • 过滤查询(因此使用过滤器)将返回相同数量的点击数。

以下是条款查询:

GET _search
{
   "query": {
      "terms": {
         "childcareTypes": [
            "SOLE_CHARGE",
            "OUT_OF_SCHOOL",
            "BABY_SITTING"
         ],
         "minimum_match": 3
      }
   }
}

以下是已过滤版本:

GET _search
{
   "query": {
      "filtered": {
         "filter": {
            "terms": {
               "childcareTypes": [
                  "SOLE_CHARGE",
                  "OUT_OF_SCHOOL",
                  "BABY_SITTING"
               ],
               "execution": "and"
            }
         }
      }
   }
}

两者的总命中数为8000(与我的指数相比)。

以下是“普通”字词查询的结果:

{
   "took": 7,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 8000,
      "max_score": 5.134171,
      "hits": [
         {
            "_index": "bignibou",
            "_type": "advertisement",
            "_id": "AUs2T2lt3L5LNr7nkot2",
            "_score": 5.134171,
            "_source": {
               "childcareWorkerType": "AUXILIAIRE_PARENTALE",
               "childcareTypes": [
                  "SOLE_CHARGE",
                  "OUT_OF_SCHOOL",
                  "BABY_SITTING"
               ],
               "address": {
                  "latitude": 48.8532558,
                  "longitude": 2.36584
               },
               "giveBath": "EMPTY"
            }
         },
         ...

以下是“已过滤”查询的结果:

{
   "took": 3,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 8000,
      "max_score": 1,
      "hits": [
         {
            "_index": "bignibou",
            "_type": "advertisement",
            "_id": "AUs2T2lt3L5LNr7nkot2",
            "_score": 1,
            "_source": {
               "childcareWorkerType": "AUXILIAIRE_PARENTALE",
               "childcareTypes": [
                  "SOLE_CHARGE",
                  "OUT_OF_SCHOOL",
                  "BABY_SITTING"
               ],
               "address": {
                  "latitude": 48.8532558,
                  "longitude": 2.36584
               },
               "giveBath": "EMPTY"
            }
         },
         ....

那么两者之间有什么区别?

1 个答案:

答案 0 :(得分:2)

这与查询过滤器more information here)之间的差异有关。

在您的情况下,与terms查询不同,terms过滤器:

  • 缓存
  • 无法计算得分:所有匹配的文档都具有相同的_score 1(查看结果)

因此,最大的区别是filtered查询会比普通的查询更快。 terms查询。