ElasticSearch筛选的查询未返回预期/期望的分数结果

时间:2015-03-06 18:39:17

标签: elasticsearch

查询 iPad Mini 3 64GB AT& T

时,ElasticSeach未返回所需的结果

ElasticSearch得分最高的是 iPad Mini 2 64GB AT& T iPad Mini 3 64GB AT& T 在搜索结果中排名第5。

以下是BrandAndDeviceName的映射部分:

"BrandAndDeviceName": {
     "type": "string",
     "fields": {
        "autocomplete": {
           "type": "string",
           "analyzer": "autocomplete"
        }
     }
},

和REST通话

GET /devices/device/_search/
{
  "query": {
    "filtered": {
      "query": {
        "query_string": {
          "query": "iPad Mini 3 64GB AT&T",
          "default_field": "BrandAndDeviceName.autocomplete"
        }
      },
      "filter": {
        "and": [
          {
            "term": {
              "Active": true
            }
          }
        ]
      }
    }
  },
  "size": 12,
  "from": 0
}

这是最佳结果

{
        "_index": "devices",
        "_type": "device",
        "_id": "94698082-d5cb-4f54-829e-dc62e196c894",
        "_score": 9.904099,
        "_source": {
           "DeviceId": "94698082-d5cb-4f54-829e-dc62e196c894",
           "DeviceName": "iPad Mini 2 64GB AT&T",
           "Active": true,
           "Brand": {
              "Id": "7d04b58b-3f2d-4f63-821f-7f081d7f1bd9",
              "Name": "Apple"
           },
           "Category": {
              "CategoryId": "41d45e60-9587-4dd9-828f-5dacf02a499f",
              "CategoryName": "Tablets"
           },
           "DeviceGroup": {
              "Id": "b362318d-5c24-4dd9-a371-3261c6b38ac6",
              "Name": "iPad Mini 2"
           },
           "BrandAndDeviceName": "Apple iPad Mini 2 64GB AT&T"
        }
 },

请注意,返回 iPad Mini 2 64GB AT& T ,得分最高为9.904099,预期文件为第5个返回,得分为9.483598

{
            "_index": "devices",
            "_type": "device",
            "_id": "5dd038b7-1dea-491d-8d69-fb349970b8a2",
            "_score": 9.483598,
            "_source": {
               "DeviceId": "5dd038b7-1dea-491d-8d69-fb349970b8a2",
               "DeviceName": "iPad Mini 3 64GB AT&T",
               "Active": true,
               "Brand": {
                  "Id": "7d04b58b-3f2d-4f63-821f-7f081d7f1bd9",
                  "Name": "Apple"
               },
               "Category": {
                  "CategoryId": "41d45e60-9587-4dd9-828f-5dacf02a499f",
                  "CategoryName": "Tablets"
               },
               "BrandAndDeviceName": "Apple iPad Mini 3 64GB AT&T"
            }
         },

为什么 Apple iPad Mini 2 64GB AT& T 得分高于 Apple iPad Mini 3 64GB AT& T

1 个答案:

答案 0 :(得分:1)

筛选查询未被删除;他们只是通过/失败。

  

过滤器通常比查询更快,因为它们不必为每个文档计算相关性_score - 答案只是布尔“是,文档与过滤器匹配”或“否,文档与过滤器不匹配” ”

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html

如果您想获得评分结果,只需使用查询,而不是过滤器。

GET /devices/device/_search/
{
  "query": {
    "query_string": {
      "query": "iPad Mini 3 64GB AT&T",
      "default_field": "BrandAndDeviceName.autocomplete"
    }
  },
  "filter": {
    "and": [
      {
        "term": {
          "Active": true
        }
      }
    ]
  },
  "size": 12,
  "from": 0
}