一個簡單的,安全的,ElasticSearch查詢編譯器:FiltrES.js

jopen 9年前發布 | 23K 次閱讀 ElasticSearch 搜索引擎 FiltrES.js

一個簡單的,安全的,ElasticSearch查詢引擎,讓你或你的最終用戶輸入任意表達式,而不需要學習ElasticSearch查詢語言。

(height <= 73 or (favorites.color == "green" and height != 73)) and firstname ~= "o.+"

特性

  • Simple! End user expression language looks like this transactions <= 5 and profit > 20.5
  • Fast! Expressions get compiled into native ElasticSearch queries, offering the same performance as if it had been hand coded. e.g. {"filtered" : {"filter" : {"bool" : {"must" : {"term" : { "tag" : "wow" }}, "must_not" : {"range" : {"age" : { "from" : 10, "to" : 20 }}}
  • Safe! Expressions cannot escape the sandbox client-side or inside of ElasticSearch.
  • Predictable! Because users can't define loops or recursive functions, you know you won't be left hanging.

10 秒教程(using ElasticSearchClient)

// A search filter
var expression = 'transactions <= 5 and profit > 20.5';

// Compile expression to executable function
var myQuery = filtres.compile(expression);

// Execute query
esc.search("filtres", "accounts", myQuery, function (err, accounts) {
    ...
});

項目主頁:http://www.baiduhome.net/lib/view/home/1418373039042

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!