一个简单的,安全的,ElasticSearch查询编译器:FiltrES.js

jopen 9年前

一个简单的,安全的,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.open-open.com/lib/view/home/1418373039042