2013-03-01 8 views
6

Was mich derzeit verwirrt, ist, dass ich in der Abfrage einen Boost zu category_id von 10 hinzufügen, der viel höher ist als die anderen Boosts. Ein Gegenstand aus einer anderen Kategorie, "Tai Chi", kommt irgendwie an die Spitze der Ergebnisse.Boost für eine Bool-Abfrage auf Elasticsearch mit wenig Wirkung

Ich habe eine Abbildung von:

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

ich die folgenden Abfrage leite:

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

Das hat mir folgenden Treffer gibt:

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

Wenn ich die category_id steigern Feld zu etwas albern wie 30 dann klopft es "Tai Chi" aus den Top-Ergebnissen. Ich möchte tatsächlich "Thai Chi" in den Suchergebnissen angezeigt werden, wenn es nichts anderes gibt, aber es scheint, dass aus irgendeinem mir unbekannten Grund der category_id Teil der Abfrage nicht richtig funktioniert. Weiß jemand, warum das passiert?

+3

Können Sie Ihre Abfragen mit explain = true Flag erneut ausführen? Es wird gezeigt, wie diese Punkte berechnet wurden. – imotov

+0

Vielen Dank, das hat mich auf den richtigen Weg gebracht. Wahrscheinlich eher ein Lucene-Scoring-Problem als ein Elasticsearch-Problem. Ich werde aktualisieren, wenn ich eine sinnvolle Antwort habe. – unflores

Antwort

7

Ich wollte den Score basierend auf einem Boost ändern, den ich der Abfrage hinzugefügt habe. Allerdings berücksichtigt die Partitur einige Dinge, nicht nur den Boost. Um einen Boost für Kategorie und Marke zu erzwingen, benutzte ich den "custom_boost_factor" und wandte ihn als Unterabfrage an, die an die regulären Fälle angehängt wurde.

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