8

目前让我感到困惑的是,在查询中我添加了category_id10 的提升,这比其他提升要高得多。另一个类别的项目“太极”,不知何故到达了结果的顶部。

我有一个映射:

{
  "the_items": {
    "item": {
      "properties": {
        "brand_id": {
          "type": "integer"
        },
        "category_id": {
          "type": "integer"
        },
        "description": {
          "type": "multi_field",
          "fields": {
            "description": {
              "type": "string",
              "analyzer": "full_title"
            }
          }
        },
        "title": {
          "type": "multi_field",
          "fields": {
            "title": {
              "type": "string",
              "analyzer": "full_title"
            },
            "partial_title": {
              "type": "string",
              "index_analyzer": "partial_title",
              "search_analyzer": "full_title",
              "include_in_all": false
            }
          }
        },
        "updated_at": {
          "type": "string"
        }
      }
    }
  }
}

我正在运行以下查询:

curl -XGET 'http://localhost:9200/austin_items/_search?pretty=true' -d '{
  "query": {
    "filtered": {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "title": {
                  "boost": 2,
                  "query": "chi",
                  "type": "phrase"
                }
              }
            },
            {
              "match": {
                "title.partial_title": {
                  "boost": 1,
                  "query": "chic"
                }
              }
            },
            {
              "match": {
                "description": {
                  "boost": 0.2,
                  "query": "chic"
                }
              }
            },
            {
              "term": {
                "category_id": {
                  "boost": 10,
                  "value": 496
                }
              }
            }
          ]
        }
      }
    }
  }
}'

这给了我以下命中:

[
  {
    "_index": "the_items",
    "_type": "item",
    "_id": "34410",
    "_score": 0.7510745,
    "_source": {
      "id": "34410",
      "title": "Initiez-vous au Tai Chi",
      "description": "p. Le Tai Chi est un art chevaleresque, initialement originaire de Chine, maintenant partie int\u00e9grante des tr\u00e9sors du patrimoine de l'humanit\u00e9. C'est un art de droiture, un art pour les braves, \u00e0 la recherche du geste juste et de l'attitude juste - la \"ju",
      "brand_id": "0",
      "category_id": "497"
    }
  },
  {
    "_index": "the_items",
    "_type": "item",
    "_id": "45393",
    "_score": 0.45193857,
    "_source": {
      "id": "45393",
      "title": "Very Hot Chicken",
      "description": "Laissez-vous tenter par la force du Very Hot Chicken Burger, avec sa sauce piment\u00e9e, ses rondelles de piment vert et sa pr\u00e9paration pan\u00e9e au poulet.\r\nAjoutez-y une tranche de chester fondu, de la salade, des tomates, le tout dans un pain parsem\u00e9 de bl\u00e9 concass\u00e9 pour un burger fort en go\u00fbt !",
      "brand_id": "0",
      "category_id": "496"
    }
  }
]

如果我将这个category_id领域提升到 30 之类的傻事,那么它会将“太极”从顶级结果中剔除。我确实希望“Thai Chi”出现在搜索结果中,以防万一,但似乎出于某种我不知道的原因,查询的 category_id 部分无法正常工作。有谁知道为什么会这样?

4

1 回答 1

9

我希望根据添加到查询中的提升来修改分数。但是,分数不仅考虑了提升,还考虑了很多事情。为了强制提升类别和品牌,我最终使用了“custom_boost_factor”并将其作为子查询应用到常规应该案例中。

curl -XGET 'http://localhost:9200/austin_items/_search?pretty=true' -d '
{
  "query" : {
    "filtered" : {
      "query" : {
        "bool" : {
          "should" : [
            { "match" : { "title" : { "boost" : 2,"query" : "chi", "type":"phrase"} } },
            { "match" : { "title.partial_title" : { "boost" : 1,"query" : "chi"} } },
            { "match" : { "description" : { "boost" : 0.2,"query" : "chic"} } },
            { "custom_boost_factor": { 
                "query":{
                  "bool": {
                    "must" : [
                      { "multi_match": { "query" : "chi", "fields" : ["title", "description"] }},
                      { "in": { "category_id": [496] } }
                    ]
                  }
                },
                "boost_factor": 2 
              }
            },
            { "custom_boost_factor": { 
                "query":{
                  "bool": {
                    "must" : [
                      { "multi_match": { "query" : "chi", "fields" : ["title", "description"] }},
                      { "in": { "brand_id": [999] } }
                    ]
                  }
                },
                "boost_factor": 3
              }
            }
          ]
        }
      }
    }
  }
}'
于 2013-03-05T14:13:01.910 回答