Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes - #862 Elasticsearch Integration fix #863

Merged
merged 1 commit into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/elasticsearch.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ include::../build/generated-documentation/apoc.es.csv[]

[source,cypher]
----
call apoc.es.post("localhost","tweets","users","1",null,{name:"Chris"})
call apoc.es.post("localhost","tweets","users",null,{name:"Chris"})
----
[source,cypher]
----
call apoc.es.put("localhost","tweets","users","1",null,{name:"Chris"})
----

[source,cypher]
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/apoc/es/ElasticSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.neo4j.procedure.Name;
import org.neo4j.procedure.Procedure;

import java.util.Collections;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -167,13 +168,21 @@ public Stream<MapResult> postRaw(@Name("host") String hostOrKey, @Name("path") S

@Procedure
@Description("apoc.es.post(host-or-port,index-or-null,type-or-null,query-or-null,payload-or-null) yield value - perform a POST operation on elastic search")
public Stream<MapResult> post(@Name("host") String hostOrKey, @Name("index") String index, @Name("type") String type, @Name("id") String id, @Name("query") Object query, @Name("payload") Object payload) {
return LoadJson.loadJsonStream(getQueryUrl(hostOrKey, index, type, id, query), map("method", "POST","content-type",contentType(payload)), toPayload(payload));
public Stream<MapResult> post(@Name("host") String hostOrKey, @Name("index") String index, @Name("type") String type, @Name("query") Object query, @Name(value = "payload", defaultValue = "{}") Map<String,Object> payload) {
if (payload == null)
{
payload = Collections.emptyMap();
}
return LoadJson.loadJsonStream(getQueryUrl(hostOrKey, index, type, null, query), map("method", "POST","content-type",contentType(payload)), toPayload(payload));
}

@Procedure
@Description("apoc.es.put(host-or-port,index-or-null,type-or-null,id-or-null,query-or-null,payload-or-null) yield value - perform a PUT operation on elastic search")
public Stream<MapResult> put(@Name("host") String hostOrKey, @Name("index") String index, @Name("type") String type, @Name("id") String id, @Name("query") Object query, @Name("payload") Object payload) {
public Stream<MapResult> put(@Name("host") String hostOrKey, @Name("index") String index, @Name("type") String type, @Name("id") String id, @Name("query") Object query, @Name(value = "payload", defaultValue = "{}") Map<String,Object> payload) {
if (payload == null)
{
payload = Collections.emptyMap();
}
return LoadJson.loadJsonStream(getQueryUrl(hostOrKey, index, type, id, query), map("method", "PUT","content-type",contentType(payload)), toPayload(payload));
}
}