2017-12-19 7 views
1

frontendにはanglejsを使用し、バックエンドにはloopbackを使用し、データベースには弾性検索を使用しています。 、オープン処理近いかもしれループバックカスタム注文by

{ 
"_index": "XXXXXX", 
"_type": "XXXXX", 
"_id": "XXXXXXX", 
"_version": 1, 
"_score": 1, 
"_source": { 
    "name": "aadil kirana", 
    "email": "[email protected]", 
    "message": "dfgfb dgfggf", 
    "quantity": 3434, 
    "price": 5454, 
    "status": "open", 
    "createdAt": "2017-12-19T14:53:41.727Z", 
    "updatedAt": "2017-12-19T14:53:41.727Z" 
    } 
} 

ステータス

データとして

"name": { 
    "type": "string", 
    "required": true 
}, 
"mobileNumber": { 
    "type": "string", 
    "required": true 
}, 
"email": { 
    "type": "string" 
}, 
"message": { 
    "type": "string", 
    "required": true 
}, 
"quantity": { 
    "type": "number", 
    "required": true 
}, 
"price": { 
    "type": "number", 
    "required": true 
}, 
"status": { 
    "type": "string", 
    "required": true, 
    "default": "open" 
} 

}:

Iは、のような特性を持つモデルを有します拒否およびのエラー

私が欲しいのは、私がcreatedAt日までに注文したすべてのオープンステータスデータを見ることができるために、データを取得するように やDAT createdAt順 すべてprcoessingステータスデータ..です..

私のようにループバック・フィルターを使用してみました:

filter = { 
       order: ['status ASC','createdAt DESC'], 
      }; 

が、これはまず、日付別に並べられた近いステータスデータ、そして、すべての目を私に与えますe ステータスデータは日付順に並べられ、アルファベット順に表示されます。

希望の結果を得るのを手伝ってください。

+1

は、(1)loopback-によって構築されている実際のESクエリを追跡esコネクタ。ロギングフレームワークは名前空間によるロギングを有効にする 'debug'であるため、ログに吐き出すことは可能です。 (2)望む結果が得られるまで、その質問を取り、それを直接修正してください。これは、ES DSLをよりよく理解する必要があります。 (3)loopback-es-connectorの作成者に、調整した生のESクエリをpingして、適切な結果を得ます。コネクターを拡張するか、コネクターにそのような照会で終わるように指示する方法を教えてください。 – pulkitsinghal

+0

ステータス番号 – Mehari

+0

の番号を使用する@Mehariあなたは、ステータス= 1、処理= 2などのようにステータスにIDを割り当てることを割り当てることを意味しますか? –

答えて

0

あなたはstatusOrderとして、あなたのデータに新しいプロパティを追加して定義することができ

  • 1 - >オープン - statusOrderによって>近くに
  • ...

と順序ステータスの注文時にステータスの代わりに

+0

はい、 'status-id'という名前で考えましたが、これは回避策であり、私のプロダクトデータも変更する必要があります。 –

+0

データをループしてコントローラでstatusOrderを設定することができる運用データを変更する必要はありません。 – NTP

+0

しかし、その場合は、まず、バックエンドからページネーションを処理する際に問題になります。 第2に、オーバーヘッドであり、パフォーマンスが低下します。 –

0

私が欲しいのは、私がcreatedAt DATなどで注文したすべてのprcoessing ステータスデータ、その後、createdAt日までに注文したすべての オープンステータスデータを見ることができるために、データを取得することです....

この問題を回避するには、Elasticsearchにカスタム注文でソートを実行させることができます。この文脈でステータスが続い近い続い処理続いオープンとして注文することができ失敗続いを拒否。これはFunction Score Queryで行うことができます。いくつかのより多くの洞察も一括挿入のためのhere

サンプルの入力データを見つけることができます。弾性検索(カスタムオーダーなし)から

POST custom/sort/_bulk?pretty 
{"index" : {"_index" : "custom"}} 
{"status": "open", "createdAt": "2017-12-19T14:53:41.727Z"} 
{"index" : {"_index" : "custom"}} 
{"status": "open", "createdAt": "2017-12-18T14:53:41.727Z"} 
{"index" : {"_index" : "custom"}} 
{"status": "processing", "createdAt": "2017-12-19T14:53:41.727Z"} 
{"index" : {"_index" : "custom"}} 
{"status": "processing", "createdAt": "2017-12-17T14:53:41.727Z"} 
{"index" : {"_index" : "custom"}} 
{"status": "close", "createdAt": "2017-12-19T14:53:41.727Z"} 
{"index" : {"_index" : "custom"}} 
{"status": "close", "createdAt": "2017-12-19T15:53:41.727Z"} 
{"index" : {"_index" : "custom"}} 
{"status": "failure", "createdAt": "2017-12-19T10:53:41.727Z"} 
{"index" : {"_index" : "custom"}} 
{"status": "failure", "createdAt": "2017-12-19T14:59:41.727Z"} 
{"index" : {"_index" : "custom"}} 
{"status": "reject", "createdAt": "2017-12-19T14:53:40.727Z"} 
{"index" : {"_index" : "custom"}} 
{"status": "reject", "createdAt": "2017-12-19T14:53:41.727Z"} 

サンプル応答:

問合せ:

GET custom/sort/_search?filter_path = took、hits.total、hits.hits._score、hits.hits._source

カスタム順序を模倣する

問合せ:

GET custom/sort/_search?filter_path=took,hits.hits._id,hits.hits._score,hits.hits._source,hits.hits.sort 
{ 
    "query": { 
    "function_score": { 
     "boost_mode": "replace", 
     "query": { 
     "constant_score": { 
      "filter": { 
      "terms": { 
       "status.keyword": [ 
       "open", 
       "processing", 
       "close", 
       "reject", 
       "failure" 
       ] 
      } 
      } 
     } 
     }, 
     "functions": [ 
     { 
      "filter": { 
      "term": { 
       "status.keyword": "open" 
      } 
      }, 
      "weight": 4 
     }, 
     { 
      "filter": { 
      "term": { 
       "status.keyword": "processing" 
      } 
      }, 
      "weight": 3 
     }, 
     { 
      "filter": { 
      "term": { 
       "status.keyword": "close" 
      } 
      }, 
      "weight": 2 
     }, 
     { 
      "filter": { 
      "term": { 
       "status.keyword": "reject" 
      } 
      }, 
      "weight": 1 
     }, 
     { 
      "filter": { 
      "term": { 
       "status.keyword": "failure" 
      } 
      }, 
      "weight": 0 
     } 
     ] 
    } 
    }, 
    "sort": [ 
    { 
     "_score": { 
     "order": "desc" 
     }, 
     "createdAt": { 
     "order": "asc" 
     } 
    } 
    ] 
} 

(カスタムオーダーで)出力:

{ 
    "took": 4, 
    "hits": { 
    "hits": [ 
     { 
     "_id": "grOucmABwtSchlgLKlaV", 
     "_score": 4, 
     "_source": { 
      "status": "open", 
      "createdAt": "2017-12-18T14:53:41.727Z" 
     }, 
     "sort": [ 
      4, 
      1513608821727 
     ] 
     }, 
     { 
     "_id": "gbOucmABwtSchlgLKlaV", 
     "_score": 4, 
     "_source": { 
      "status": "open", 
      "createdAt": "2017-12-19T14:53:41.727Z" 
     }, 
     "sort": [ 
      4, 
      1513695221727 
     ] 
     }, 
     { 
     "_id": "hLOucmABwtSchlgLKlaV", 
     "_score": 3, 
     "_source": { 
      "status": "processing", 
      "createdAt": "2017-12-17T14:53:41.727Z" 
     }, 
     "sort": [ 
      3, 
      1513522421727 
     ] 
     }, 
     { 
     "_id": "g7OucmABwtSchlgLKlaV", 
     "_score": 3, 
     "_source": { 
      "status": "processing", 
      "createdAt": "2017-12-19T14:53:41.727Z" 
     }, 
     "sort": [ 
      3, 
      1513695221727 
     ] 
     }, 
     { 
     "_id": "hbOucmABwtSchlgLKlaV", 
     "_score": 2, 
     "_source": { 
      "status": "close", 
      "createdAt": "2017-12-19T14:53:41.727Z" 
     }, 
     "sort": [ 
      2, 
      1513695221727 
     ] 
     }, 
     { 
     "_id": "hrOucmABwtSchlgLKlaV", 
     "_score": 2, 
     "_source": { 
      "status": "close", 
      "createdAt": "2017-12-19T15:53:41.727Z" 
     }, 
     "sort": [ 
      2, 
      1513698821727 
     ] 
     }, 
     { 
     "_id": "ibOucmABwtSchlgLKlaV", 
     "_score": 1, 
     "_source": { 
      "status": "reject", 
      "createdAt": "2017-12-19T14:53:40.727Z" 
     }, 
     "sort": [ 
      1, 
      1513695220727 
     ] 
     }, 
     { 
     "_id": "irOucmABwtSchlgLKlaV", 
     "_score": 1, 
     "_source": { 
      "status": "reject", 
      "createdAt": "2017-12-19T14:53:41.727Z" 
     }, 
     "sort": [ 
      1, 
      1513695221727 
     ] 
     }, 
     { 
     "_id": "h7OucmABwtSchlgLKlaV", 
     "_score": 0, 
     "_source": { 
      "status": "failure", 
      "createdAt": "2017-12-19T10:53:41.727Z" 
     }, 
     "sort": [ 
      0, 
      1513680821727 
     ] 
     }, 
     { 
     "_id": "iLOucmABwtSchlgLKlaV", 
     "_score": 0, 
     "_source": { 
      "status": "failure", 
      "createdAt": "2017-12-19T14:59:41.727Z" 
     }, 
     "sort": [ 
      0, 
      1513695581727 
     ] 
     } 
    ] 
    } 
}