elasticsearch - APOC Elasticsearch 查询格式
问题描述
我正在使用 Neo4j 4.0.3、Elasticsearch 6.8.3 和 APOC。
我想使用 APOC Elasticsearch 过程通过 Neo4J 运行 Elasticsearch 聚合查询。
该查询在请求正文中定义并适用于 Elasticsearch,但我不确定如何通过该过程构造查询参数。在 Elasticsearch 中,我可以将请求正文作为源参数(源内容类型为 JSON)传递。
为了演示,我试图让一个简单的查询正常工作。
这适用于 Elasticsearch:
GET http://localhost:9200/trends/trend/_search?source={"query": {"match" : {"type" : "ENTITY"}}}&source_content_type=application/json
但是当我通过 ES 程序尝试这个时:
CALL apoc.es.query('elasticsearch:9200', 'trends', 'trend', 'source={"query":{"match":{"type":"ENTITY"}}}&source_content_type=application/json', null)
Neo4J 给出以下错误:
Failed to invoke procedure `apoc.es.query`: Caused by: java.net.URISyntaxException: Illegal character in query at index 54: http://elasticsearch:9200/trends/trend/_search?source={"query":{"match":{"type":%22ENTITY%22%7D%7D%7D````
我需要做什么才能正确传递查询?
解决方案
如果您想使用滚动 ID 和有效负载来指定查询,则可以使用以下方法:
CALL apoc.es.query('localhost','indexName','doc','scroll=1m','{
"query":{
"query_string":{
"query": "name:somebody AND date:[now-30d TO now]"
}
},
"size":"1000"
}') yield value
with value._scroll_id as scrollId, value.hits.hits as hits
// Do something with hits
UNWIND hits as hit
return hit
这种格式使编辑查询更容易:当将查询放在第四个参数位置的字符串中时,我发现不一致的结果和 URL 转义规则。
请参阅https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html和https://neo4j.com/docs/labs/apoc/4.0/database-integration/elasticsearch /
推荐阅读
- javascript - 无法使用此 onclick 功能显示 p 标签
- python - Python,从数据输入中添加两个值
- swift - 如何在 MVVM 中将 PublishSubject 呈现为 Observable?
- c# - UWP 应用中出现随机主页按钮
- android - 如何更改按钮背景和文本颜色?
- rhapsody - IBM Rhational Rhapsody 中的外部库文件
- windows - 如何使用 Windows 批处理提取 GIT 日志
- mongodb - Mongodb $unwind 聚合不起作用
- python - 如何在python中搜索列表的第一个元素
- postgresql - postgres 更新 v297 后 Heroku 连接泄漏