2016-04-22 7 views
-1

に私はelasticsearchで、この文のSQLのようにしてください。しかしelasticsearch

select * from user where (name like '%juan%') and position = 2 and catid  in (4,3,76453,345,345,345345,345) and prof = 9 

これは私が

{ 
"size": 25, 
"query": 
{ 
    "filtered": 
    { 
     "filter": 
     { 
      "and": 
      [ 
       { "term": { "user":"juan" } }, 
       { "term": { "position":"2" } }, 

       { 
        "or": 
        [ 
         { "term": { "catid":"4" } }, 
         { "term": { "catid":"3" } } 
        ] 
       } 
      ] 
     } 
    } 
} 

を使用しました例の一つである私に実行しないする必要が入れ子になったと、またはと同じようにする方法他

}

"query": { 
    "filtered": { 

     "filter": { 
      "bool": { 
       "must": [ 
{ 
"bool": { 
         "should": [{ 
          "term": { 
           "name": "juan" 

          } 
         }] 
        } 
       }, 
       { 
        "bool": { 
         "should": [{ 
          "term": { 
           "position": "2" 
          } 
         }] 
        } 
       } 

       ] 
      }, 
      "or": 
      [ 
       { "term": { "catid":"4" } }, 
       { "term": { "catid":"3" } } 
      ]       
     }  



    } 
}, 
"size": 1000 
} 

私は本当に単語を検索する必要があります。多くの変数を使用して、ここには少なくとも10個以上のすべての時間を入れません。

+0

を動作するようですか? –

+0

バージョンは2.3.1、今すぐインストール –

答えて

0

フィルタはElasticsearch 2.0で削除されています。 。

  • (得点を含むフィルタクエリに相当)フィルタ句
  • 使用constant_score queryで使用bool query(得点なしフィルタクエリに相当)
:あなたはフィルタリングする場合は、あなたは今、2つのオプションがあり

さらに、推奨されなくなり、すぐに削除されるので、またはのクエリは避ける必要があります。

SQLクエリについては、私はそのようにそれを翻訳したい:

"query": { 
    "bool": { 
     "filter": { 
     "bool": { 
      "must": [ 
      { 
       "match": { "user": "juan" } 
      }, 
      { 
       "term": { "position":"2" } 
      }, 
      { 
       "terms": { 
       "catid": [4,3,76453,345] 
       } 
      } 
      ] 
     } 
     } 
    } 
    } 

その用語-クエリを注意してください、あなたのフィールド上の正確なマッチを行います!たとえばユーザーフィールドには複数の単語を含む名前が含まれています。用語クエリは、期待される結果を返しません。この場合、match-queryを使用してください。

+0

うわー私はバージョン1.1.1を持っています...私はこのバージョンを持っていることに驚いています –

+0

OK、ES 1.xソリューションも必要ですか?とにかくES 2.x? –

+0

現時点では、このソリューションでは1. *を必要とし、開発サーバーで更新する予定があるため、更新できません –

0

あなたがelasticsearchのどのバージョンを使用してください

{ 
"query": { 
     "filtered": { 

     "filter": { 
      "bool": { 
       "must": [ 
       { 
        "numeric_range": {"stocktotal": {"gte": 2,"lte": 99999999999}} 
       } 
       , 
       { 
        "term": { "cat_name":"limpiadoasabarra_derechabarra_derechaapulidoras__de__superficies" } 
       }, 
       {"terms": {"supplier_id": [8634, 916]}} 
       ] 

     }    
    } 
}, 
"size" : 1000, 
"aggs" : { 
    "etiquetas" : {"terms" : { "field" : "supplier_name" }, "size" : 20 }, 
    "nombre_familia" : {"terms" : { "field" : "nombre_familia", "size" : 20 }}, 
    "nombre_subfamilia" : {"terms" : { "field" : "nombre_subfamilia", "size" : 20 }}, 
    "cat_name" : {"terms" : { "field" : "cat_name" }, "size" : 20} 

} 
}