2013-03-01 15 views
6

現在、私はクエリで、category_idのブーストを追加して、他のブーストよりもはるかに高いことがわかりました。別のカテゴリ「太極拳」のアイテムは、結果の上部に何とか到着します。私はcategory_idを後押しした場合ElasticsearchのBoolクエリのブーストにはほとんど影響がありません

[ 
    { 
    "_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" 
    } 
    } 
] 

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 
       } 
       } 
      } 
      ] 
     } 
     } 
    } 
    } 
}' 

私に次のヒットを与える:私は次のクエリを実行しています

{ 
    "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" 
     } 
     } 
    } 
    } 
} 

私はのマッピングを持っていますフィールドは30のような愚かな何かにそれはトップ結果の "太極拳"をノックする。私は実際には「タイのχ」が検索結果に表示されることを願っていますが、それ以外は何もありませんが、クエリのcategory_id部分が正しく機能していないことがわかっています。誰がなぜこれが起こっているのか知っていますか?

+3

explain = trueフラグを使用してクエリを再実行できますか?このスコアがどのように計算されたかを示します。 – imotov

+0

おかげで、これは私を正しい軌道に乗せてくれました。おそらく弾性探査問題よりもルーシンスコアリングの問題が多い。私は価値ある答えがあるときに更新します。 – unflores

答えて

7

私は質問に追加したブーストに基づいてスコアを修正しようとしていました。しかし、スコアは、ブーストだけでなく、多くのことを考慮に入れています。カテゴリとブランドを強化するために、 "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 
       } 
      } 
      ] 
     } 
     } 
    } 
    } 
}' 
関連する問題