2016-05-22 14 views
0

キーワードごとにboostフィーチャを適用した後に、特定の検索キーワードone two threeのES検索結果が間違っているようです。上記の「期待される結果」を達成するために、「不完全な」クエリを修正する手助けをしてください。 three最も重要なキーワードとみなされている - 私は、ESにLUCENE が基準後押し4.10.4弾性検索クエリの時間増強により不適切な順序で結果が生成される

1.7.4だ:

word - boost 
---- ----- 
one 1 
two 2 
three 3 

ESインデックスコンテンツを - ポストを短くするMySQLダンプを表示するだけです

mysql> SELECT id, title FROM post; 
+----+-------------------+ 
| id | title    | 
+----+-------------------+ 
| 1 | one    | 
| 2 | two    | 
| 3 | three    | 
| 4 | one two   | 
| 5 | one three   | 
| 6 | one two three  | 
| 7 | two three   | 
| 8 | none    | 
| 9 | one abc   | 
| 10 | two abc   | 
| 11 | three abc   | 
| 12 | one two abc  | 
| 13 | one two three abc | 
| 14 | two three abc  | 
+----+-------------------+ 
14 rows in set (0.00 sec) 

期待ESクエリ結果からユーザーがone two threeを探しています。 私は、同じようにスコアリングされたレコードの順序について騒がしいわけではありません。レコード6と13が場所を切り替えると、私は気にしません。

+----+-------------------+ 
| id | title    | my scores for demonstration purposes 
+----+-------------------+ 
| 6 | one two three  | (1+2+3 = 6) 
| 13 | one two three abc | (1+2+3 = 6) 
| 7 | two three   | (2+3 = 5) 
| 14 | two three abc  | (2+3 = 5) 
| 5 | one three   | (1+3 = 4) 
| 4 | one two   | (1+2 = 3) 
| 12 | one two abc  | (1+2 = 3) 
| 3 | three    | (3 = 3) 
| 11 | three abc   | (3 = 3) 
| 2 | two    | (2 = 2) 
| 10 | two abc   | (2 = 2) 
| 1 | one    | (1 = 1) 
| 9 | one abc   | (1 = 1) 
| 8 | none    | <- This shouldn't appear 
+----+-------------------+ 
14 rows in set (0.00 sec) 

予期しないESクエリ結果から残念ながら、これは私が得るものです。

+----+-------------------+ 
| id | title    | _score 
+----+-------------------+ 
| 6 | one two three  | 1.0013864 
| 13 | one two three abc | 1.0013864 
| 4 | one two   | 0.57794875 
| 3 | three    | 0.5310148 
| 7 | two three   | 0.50929534 
| 5 | one three   | 0.503356 
| 14 | two three abc  | 0.4074363 
| 11 | three abc   | 0.36586377 
| 12 | one two abc  | 0.30806428 
| 10 | two abc   | 0.23231897 
| 2 | two    | 0.12812772 
| 1 | one    | 0.084527075 
| 9 | one abc   | 0.07408653 
+----+-------------------+ 

ESクエリ

curl -XPOST "http://127.0.0.1:9200/_search?post_dev" -d' 
{ 
    "query": { 
    "bool": { 
     "must": { 
     "match": { 
      "title": { 
      "query": "one two three" 
      } 
     } 
     }, 
     "should": [ 
     { 
      "match": { 
      "title": { 
       "query": "one", 
       "boost": 1 
      } 
      } 
     }, 
     { 
      "match": { 
      "title": { 
       "query": "two", 
       "boost": 2 
      } 
      } 
     }, 
     { 
      "match": { 
      "title": { 
       "query": "three", 
       "boost": 3 
      } 
      } 
     } 
     ] 
    } 
    }, 
    "sort": [ 
    { 
     "_score": { 
     "order": "desc" 
     } 
    } 
    ], 
    "from": "0", 
    "size": "100" 
}' 

いくつかのより多くのテストクエリ:

  • このqueryは、任意の結果を生成しません。
  • queryは正しく表示されません。hereと表示されます。
+0

予想される出力はどのように決定しましたか? "three"が最も重要なキーワードである場合、 "one two"はどのように "three"の前に来るのでしょうか?あなたが知る必要があることは、ブースティングが線形ではないということです。あなたが2で質問を押し上げると、前回のスコアの2倍になるでしょう。これは主に正規化プロセスによるものです。どのようにあなたの期待に結びつくかについてより意味のあるフィードバックを提供するならば、私は再度クエリを手助けしようとすることができます。 – Heval

+0

@Heval私の期待は、自分自身の制限された知識に基づいてあいまいであるかもしれないので、正確に何が必要なのかを教えてください。単語の大部分を含む 'title'があれば良いです。例えば、「one two three(= 6)点」が「three」(3点)より良好であるか、「two three」(5)が「one three」(4)または「one 3(5)は3より良い(3)。私はあなたがその写真を得ることを望む。私は '' query ':["one"、 "two"、 "three"] 'を使用しましたが、どちらもうまくいきませんでした。とにかく、私はあなたのために今それを残す。ありがとうございました – BentCoder

+0

私はまた、より良い説明を提供するために、上記の "Expected ES query result"のセクションを更新しました。 – BentCoder

答えて

3
# Index some test data 
curl -XPUT "localhost:9200/test/doc/1" -d '{"title": "one"}' 
curl -XPUT "localhost:9200/test/doc/2" -d '{"title": "two"}' 
curl -XPUT "localhost:9200/test/doc/3" -d '{"title": "three"}' 
curl -XPUT "localhost:9200/test/doc/4" -d '{"title": "one two"}' 
curl -XPUT "localhost:9200/test/doc/5" -d '{"title": "one three"}' 
curl -XPUT "localhost:9200/test/doc/6" -d '{"title": "one two three"}' 
curl -XPUT "localhost:9200/test/doc/7" -d '{"title": "two three"}' 
curl -XPUT "localhost:9200/test/doc/8" -d '{"title": "none"}' 
curl -XPUT "localhost:9200/test/doc/9" -d '{"title": "one abc"}' 
curl -XPUT "localhost:9200/test/doc/10" -d '{"title": "two abc"}' 
curl -XPUT "localhost:9200/test/doc/11" -d '{"title": "three abc"}' 
curl -XPUT "localhost:9200/test/doc/12" -d '{"title": "one two abc"}' 
curl -XPUT "localhost:9200/test/doc/13" -d '{"title": "one two three abc"}' 
curl -XPUT "localhost:9200/test/doc/14" -d '{"title": "two three abc"}' 
# Make test data available for search 
curl -XPOST "localhost:9200/test/_refresh?pretty" 
# Search using function score 
curl -XPOST "localhost:9200/test/doc/_search?pretty" -d'{ 
    "query": { 
     "function_score": { 
      "query": { 
       "match": { 
        "title": "one two three" 
       } 
      }, 
      "functions": [ 
       { 
        "filter": { 
         "query": { 
          "match": { 
           "title": "one" 
          } 
         } 
        }, 
        "weight": 1 
       }, 
       { 
        "filter": { 
         "query": { 
          "match": { 
           "title": "two" 
          } 
         } 
        }, 
        "weight": 2 
       }, 
       { 
        "filter": { 
         "query": { 
          "match": { 
           "title": "three" 
          } 
         } 
        }, 
        "weight": 3 
       } 
      ], 
      "score_mode": "sum", 
      "boost_mode": "replace" 
     } 
    }, 
    "sort": [ 
     { 
      "_score": { 
       "order": "desc" 
      } 
     } 
    ], 
    "from": "0", 
    "size": "100" 
}' 
+0

もしできれば、それ以上の+1を与えるでしょう。ありがとう、それは完璧に正常に動作します。良いことは、私が思ったように、それを数マイルで逃したことはありません! – BentCoder

関連する問題