2016-09-12 6 views
1

Node.jsでElasticsearchを使用しています。問題は、私が結果を押し上げるようなクエリを書いてほしいということです。例えば、もし私がのインデックスを持っていれば:のタイプ:レストラン、ファッション両方のタイプはフィールドショップ名を持っています、今私の検索結果を2倍に増やしたいshop_nameがファッションではなくレストランタイプで見つかった場合。私が書いてきた特定のタイプのフィールドに属している場合、結果を向上させるためのクエリを作成します。

私のクエリは、私が推測する前に、2〜3ヶ月の罰金働いていた理由が、コードの上に今、私にはわからないが、今私は、なぜコードの上知りません

index: 'merchants', 
    type: ['fashion', 'restaurant'], 
    body: { 
    "query":{ 
     bool: { 
      "disable_coord": true, 
      should: [ 
      { 
      "constant_score": { 
       boost: 1.00, // HERE BOOST IS 1 as field is in type FASHION 
       "query": { 
       "wildcard" : { "fashion.shop_name" : last_wildcard_string } 
       } 
      } 
      }, 
      { 
      "constant_score": { 
       boost: 2.00, // HERE BOOST IS 2 as field is in type RESTAURANT 
       "query": { 
       "wildcard" : { "restaurant.shop_name" : last_wildcard_string } 
       } 
      } 
      } 
      ], "minimum_should_match": 1 
     } 
    } 
    } 

以下に示します。何も返さない

誰かが正しく動作する前に間違っていることを教えてもらえますか?それ以外の場合は、を教えてください。これはfashion.shop_nameを書いて、ファッションのshop_nameを定義する正しい方法ではありませんか?

ありがとうございます。

+0

elasticsearchのどのバージョンをお試しください! elasticsearchまたはnodejs apiをアップグレードしましたか? – jay

答えて

1

この

{ 
"query" : { 
    "bool" : { 
     "should" : [{ 
       "bool" : { 
        "must" : [{ 
          "wildcard" : { 
           "shop_name" : { 
            "value" : "last_wildcard_string", 
            "boost" : 2.0 
           } 
          } 
         }, { 
          "term" : { 
           "_type" : "restaurant" 
          } 
         } 
        ] 
       } 
      }, { 
       "bool" : { 
        "must" : [{ 
          "wildcard" : { 
           "shop_name" : { 
            "value" : "last_wildcard_string", 
            "boost" : 1.0 
           } 
          } 
         }, { 
          "term" : { 
           "_type" : "fashion" 
          } 
         } 
        ] 
       } 
      } 
     ] 
    } 
} 

}

+0

本当に働いてくれてありがとう。 –

+0

うれしいよ:) – jay

関連する問題