node.js - 将 QS 查询字符串转换为弹性云查询
问题描述
有什么方法可以将使用qs npm的查询字符串转换为弹性云查询字符串?哪个支持所有类型的嵌套查询参数,大于、小于、范围之间的值所有类型的查询?
任何执行此操作的 npm 模块、git hub 代码或代码片段?示例:对于我的 api,我支持 qs npm 模块支持的所有类型的查询参数,其中我的搜索 api 是从弹性云中获取的。
所以如果我得到查询
?title=Resurgence&causes=General&location.city=Mysuru&latitude=12.9803047&longitude=77.62949349999997&distance=50000&pageNumber=0&pageSize=10& organisation._id=5c36dd152edb5028fd7655a4
然后查询字符串将由 qs npm 模块转换为 json 对象,并给出如下的 json 对象
{"title":"Resurgence","causes":"General","location.city":"Mysuru","latitude":"12.9803047","longitude":"77.62949349999997","distance":"50000","pageNumber":"0","pageSize":"10","organisation._id":"5c36dd152edb5028fd7655a4"}
在弹性搜索中搜索时,我想将其转换为弹性搜索查询对象,如下所示。所以我只是在寻找一个 npm 模块,它将 qs 模块的查询字符串 json 转换为弹性云查询体?
{
"index": "researchArticles",
"from": 0,
"size": 10,
"body": {
"query": {
"bool": {
"must": [
{
"match": {
"status": "PUBLISHED"
}
},
{
"match": {
"title": {
"query": "Resurgence",
"operator": "or",
"prefix_length": 1
}
}
},
{
"match": {
"causes": {
"query": "General",
"operator": "or",
"prefix_length": 1
}
}
},
{
"match": {
"location.city": {
"query": "Bengaluru",
"operator": "or",
"prefix_length": 1
}
}
},
{
"match": {
"pageNumber": {
"query": "0",
"operator": "or",
"prefix_length": 1
}
}
},
{
"match": {
"pageSize": {
"query": "10",
"operator": "or",
"prefix_length": 1
}
}
},
{
"match": {
"organisation._id": {
"query": "5c36dd152edb5028fd7655a4",
"operator": "or",
"prefix_length": 1
}
}
}
],
"should": {
"range": {
"startDate": {
"gte": "now"
}
}
},
"filter": {
"geo_distance": {
"distance": "50000",
"location.geoSpatial": {
"lat": "12.9803047",
"lon": "77.62949349999997"
}
}
}
}
},
"sort": [
{
"_geo_distance": {
"location.geoSpatial": "12.9803047,77.62949349999997",
"order": "asc",
"unit": "m"
}
}
]
}
}
解决方案
推荐阅读
- haskell - 消除类似 sum 类型方法之间的代码重复
- java - Java 调试在 Azure VM 上不起作用?
- f# - F# 对嵌套计算表达式的调用过多
- prolog - 尝试在 Prolog 中执行查询时超出堆栈限制
- r - 闪亮:在选择输入选项上添加悬停按钮
- php - 添加php变量的值
- express - 来自端点的 Socket.io 和 Express 回调
- batch-file - 如何使用批处理文件运行可执行文件并更改当前目录,同时保持 cmd 窗口打开
- python - 我想生成一个从 0 到 20 的随机数。遍历随机数并继续将数字添加到列表中,直到重复 & 停止 & 打印
- php - 文档下载但无法在浏览器中打开