我使用的是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````
我需要做什么才能正确地传递查询?
发布于 2020-04-29 21:58:19
让它工作,我忽略了payload
参数。所以APOC的调用是这样的:
CALL apoc.es.query('elasticsearch:9200', 'trends', 'trend', null, '{"query":{"match":{"type":"ENTITY"}}}')
或者,我可以将查询作为Map
传递
CALL apoc.es.query('elasticsearch:9200', 'trends', 'trend', apoc.map.fromPairs([
["source_content_type", "application/json"],
["source", '{"query":{"match":{"type":"ENTITY"}}}']
]), null)
发布于 2020-05-27 08:34:07
如果您希望使用滚动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/
https://stackoverflow.com/questions/61501877
复制相似问题