首页 文章

“普通”术语查询与使用过滤器的术语查询之间的差异

提问于
浏览
1

我想了解两者之间的区别:

  • a "plain" elasticsearch查询将匹配 terms 查询并返回一定数量的匹配 .

  • filtered 查询(因此使用 filter )将返回相同数量的命中 .

这是 terms 查询:

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

这是 filtered 版本:

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"
            }
         },
         ....

Then what are the differences between the two?

1 回答

  • 2

    这与 queriesfiltersmore information here)之间的差异有关 .

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

    • cached

    • doesn't compute the score :所有匹配的文件都具有相同的 _score 为1(查看结果)

    因此,最大的区别是 filtered 查询将比'plain' terms 查询更快 .

相关问题