Skip to content

Commit

Permalink
Merge branch 'master' into es_2.0
Browse files Browse the repository at this point in the history
Conflicts:
	jest-common/pom.xml
	jest-common/src/main/java/io/searchbox/core/MoreLikeThis.java
	jest-droid/pom.xml
	jest/pom.xml
  • Loading branch information
Cihat Keser committed Nov 15, 2015
2 parents df9c6f1 + d4d115f commit 21ec0bf
Show file tree
Hide file tree
Showing 16 changed files with 119 additions and 45 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Thanks
---------------------
Thanks to [JetBrains][jetbrains] for providing a license for [IntelliJ IDEA][idea] to develop this project.

<a href="https://www.jetbrains.com/idea/features/"><img src="https://www.jetbrains.com/idea/docs/logo_intellij_idea.svg" width="250 px" /></a>

We also would like to thank the following people for their significant contributions.
* [Andrea Turli](https://github.com/andreaturli)
* [Andrej Kazakov](https://github.com/andrejserafim)
Expand Down
2 changes: 0 additions & 2 deletions jest-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

<modelVersion>4.0.0</modelVersion>

<groupId>io.searchbox</groupId>
<artifactId>jest-common</artifactId>
<packaging>jar</packaging>
<version>2.0.0-SNAPSHOT</version>
<name>Jest Common Jar</name>
<description>ElasticSearch Java REST client - shared library package</description>
<url>https://github.com/searchbox-io/Jest</url>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.searchbox.action;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
import com.google.gson.Gson;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package io.searchbox.action;

import io.searchbox.params.Parameters;
import org.apache.commons.lang3.StringUtils;

import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;

/**
* @author cihat keser
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.apache.commons.lang3.StringUtils;

import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

Expand Down
15 changes: 14 additions & 1 deletion jest-common/src/main/java/io/searchbox/client/JestResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ public void setJsonMap(Map<String, Object> resultMap) {
String json = gson.toJson(resultMap, Map.class);
setJsonObject(new JsonParser().parse(json).getAsJsonObject());
}

public String getSourceAsString() {
String[] keys = getKeys();
if(!isSucceeded || jsonObject == null || keys == null || keys.length == 0 || !jsonObject.has(keys[0])) {
return null;
}

JsonElement obj = jsonObject.get(keys[0]);
for (int i = 1; i < keys.length; i++) {
obj = ((JsonObject) obj).get(keys[i]);
}
return obj.toString();
}

public <T> T getSourceAsObject(Class<T> clazz) {
T sourceAsObject = null;
Expand Down Expand Up @@ -271,7 +284,7 @@ private <T> T getAs(JsonElement id, Class<T> fieldType) throws IllegalAccessExce
}

protected String[] getKeys() {
return pathToResult == null ? null : (pathToResult + "").split("/");
return pathToResult == null ? null : pathToResult.split("/");
}

}
1 change: 0 additions & 1 deletion jest-common/src/main/java/io/searchbox/core/Bulk.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.searchbox.action.AbstractAction;
import io.searchbox.action.BulkableAction;
import io.searchbox.action.GenericResultAbstractAction;
import io.searchbox.client.JestResult;
import io.searchbox.params.Parameters;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.searchbox.action.AbstractAction;
import io.searchbox.action.GenericResultAbstractAction;

import java.io.*;
import java.nio.charset.Charset;

import static io.searchbox.indices.script.ScriptLanguage.GROOVY;
import static java.net.URLEncoder.encode;

public class CreateIndexedScript extends AbstractIndexedScript {

protected CreateIndexedScript(Builder builder) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package io.searchbox.indices.script;

import io.searchbox.action.AbstractAction;
import io.searchbox.action.GenericResultAbstractAction;

import java.io.UnsupportedEncodingException;

import static io.searchbox.indices.script.ScriptLanguage.GROOVY;
import static java.net.URLEncoder.encode;

public class DeleteIndexedScript extends AbstractIndexedScript {

protected DeleteIndexedScript(Builder builder) {
Expand Down
74 changes: 70 additions & 4 deletions jest-common/src/test/java/io/searchbox/client/JestResultTest.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package io.searchbox.client;

import static org.junit.Assert.*;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import io.searchbox.annotations.JestId;

import org.junit.Test;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import static junit.framework.Assert.*;

/**
* @author Dogukan Sonmez
*/
Expand Down Expand Up @@ -125,6 +127,70 @@ public void getGetSourceAsObject() {
assertEquals("trying out Elastic Search", twitter.getMessage());
assertEquals("2009-11-15T14:12:12", twitter.getPostDate());
}

@Test
public void getGetSourceAsString() {
String response = "{\n" +
" \"_index\" : \"twitter\",\n" +
" \"_type\" : \"tweet\",\n" +
" \"_id\" : \"1\", \n" +
" \"_source\" : {\n" +
" \"user\" : \"kimchy\",\n" +
" \"postDate\" : \"2009-11-15T14:12:12\",\n" +
" \"message\" : \"trying out Elastic Search\"\n" +
" }\n" +
"}\n";

result.setJsonMap(new Gson().fromJson(response, Map.class));
result.setPathToResult("_source");
result.setSucceeded(true);

String onlySource = "{" +
"\"user\":\"kimchy\"," +
"\"postDate\":\"2009-11-15T14:12:12\"," +
"\"message\":\"trying out Elastic Search\"" +
"}";
assertEquals(onlySource, result.getSourceAsString());
}

@Test
public void getGetSourceAsStringArray() {
String response = "{\n" +
" \"_index\" : \"twitter\",\n" +
" \"_type\" : \"tweet\",\n" +
" \"_id\" : \"1\", \n" +
" \"_source\" : [" +
" { \"user\" : \"kimch\" }, " +
" { \"user\" : \"bello\" }," +
" { \"user\" : \"ionex\" }" +
" ]\n" +
"}\n";

result.setJsonMap(new Gson().fromJson(response, Map.class));
result.setPathToResult("_source");
result.setSucceeded(true);

String onlySource = "[" +
"{\"user\":\"kimch\"}," +
"{\"user\":\"bello\"}," +
"{\"user\":\"ionex\"}" +
"]";
assertEquals(onlySource, result.getSourceAsString());
}

@Test
public void getGetSourceAsStringNoResult() {
String response = "{\n" +
" \"_index\" : \"twitter\",\n" +
" \"_type\" : \"tweet\",\n" +
" \"_id\" : \"1\" \n" +
"}\n";

result.setJsonMap(new Gson().fromJson(response, Map.class));
result.setPathToResult("_source");
result.setSucceeded(true);
assertNull(result.getSourceAsString());
}

@Test
public void getUnFoundGetResultAsAnObject() {
Expand Down Expand Up @@ -418,7 +484,7 @@ public void extractCountResult() {
result.setJsonMap(new Gson().fromJson(response, Map.class));
result.setPathToResult("count");
Double actual = result.extractSource().get(0).getAsDouble();
assertEquals(1.0, actual);
assertEquals(1.0, actual, 0.01);
}

@Test
Expand All @@ -435,7 +501,7 @@ public void getCountSourceAsObject() {
result.setPathToResult("count");
result.setSucceeded(true);
Double count = result.getSourceAsObject(Double.class);
assertEquals(1.0, count);
assertEquals(1.0, count, 0.01);
}

@Test
Expand Down
2 changes: 0 additions & 2 deletions jest-droid/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

<modelVersion>4.0.0</modelVersion>

<groupId>io.searchbox</groupId>
<artifactId>jest-droid</artifactId>
<packaging>jar</packaging>
<version>2.0.0-SNAPSHOT</version>
<name>Jest Android Jar</name>
<description>ElasticSearch Java REST client - Android library package</description>
<url>https://github.com/searchbox-io/Jest</url>
Expand Down
2 changes: 1 addition & 1 deletion jest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ String source = jsonBuilder()
as Map;

``` java
Map<String, String> source = new LinkedHashMap<String,String>()
Map<String, String> source = new LinkedHashMap<String,String>();
source.put("user", "kimchy");
```

Expand Down
2 changes: 0 additions & 2 deletions jest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

<modelVersion>4.0.0</modelVersion>

<groupId>io.searchbox</groupId>
<artifactId>jest</artifactId>
<packaging>jar</packaging>
<version>2.0.0-SNAPSHOT</version>
<name>Jest Apache HC Jar</name>
<description>ElasticSearch Java REST client - Apache HTTP Client package</description>
<url>https://github.com/searchbox-io/Jest</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ public static class Builder extends ClientConfig.AbstractBuilder<HttpClientConfi
private Integer defaultMaxTotalConnectionPerRoute;
private Map<HttpRoute, Integer> maxTotalConnectionPerRoute = new HashMap<HttpRoute, Integer>();
private CredentialsProvider credentialsProvider;
private LayeredConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactory.getSocketFactory();
private ConnectionSocketFactory plainSocketFactory = PlainConnectionSocketFactory.getSocketFactory();
private HttpRoutePlanner httpRoutePlanner = new SystemDefaultRoutePlanner(ProxySelector.getDefault());
private LayeredConnectionSocketFactory sslSocketFactory;
private ConnectionSocketFactory plainSocketFactory;
private HttpRoutePlanner httpRoutePlanner;
private AuthenticationStrategy proxyAuthenticationStrategy;
private SchemeIOSessionStrategy httpIOSessionStrategy = NoopIOSessionStrategy.INSTANCE;
private SchemeIOSessionStrategy httpsIOSessionStrategy = SSLIOSessionStrategy.getSystemDefaultStrategy();
private SchemeIOSessionStrategy httpIOSessionStrategy;
private SchemeIOSessionStrategy httpsIOSessionStrategy;

public Builder(HttpClientConfig httpClientConfig) {
super(httpClientConfig);
Expand Down Expand Up @@ -242,6 +242,22 @@ public Builder proxy(HttpHost proxy, AuthenticationStrategy proxyAuthenticationS
}

public HttpClientConfig build() {
// Lazily initialize if necessary, as the call can be expensive when done eagerly.
if (this.sslSocketFactory == null) {
this.sslSocketFactory = SSLConnectionSocketFactory.getSocketFactory();
}
if(this.plainSocketFactory == null) {
this.plainSocketFactory = PlainConnectionSocketFactory.getSocketFactory();
}
if(this.httpRoutePlanner == null) {
this.httpRoutePlanner = new SystemDefaultRoutePlanner(ProxySelector.getDefault());
}
if(this.httpIOSessionStrategy == null) {
this.httpIOSessionStrategy = NoopIOSessionStrategy.INSTANCE;
}
if(this.httpsIOSessionStrategy == null) {
this.httpsIOSessionStrategy = SSLIOSessionStrategy.getSystemDefaultStrategy();
}
return new HttpClientConfig(this);
}

Expand Down
18 changes: 9 additions & 9 deletions jest/src/main/java/io/searchbox/client/http/JestHttpClient.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
package io.searchbox.client.http;

import com.google.gson.Gson;
import io.searchbox.action.Action;
import io.searchbox.client.AbstractJestClient;
import io.searchbox.client.JestClient;
import io.searchbox.client.JestResult;
import io.searchbox.client.JestResultHandler;
import io.searchbox.client.http.apache.HttpDeleteWithEntity;
import io.searchbox.client.http.apache.HttpGetWithEntity;
import org.apache.http.HttpEntity;
import java.io.IOException;
import java.util.Map.Entry;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.client.entity.EntityBuilder;
import org.apache.http.client.methods.*;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Map.Entry;
import com.google.gson.Gson;

/**
* @author Dogukan Sonmez
* @author cihat keser
*/
public class JestHttpClient extends AbstractJestClient implements JestClient {
public class JestHttpClient extends AbstractJestClient {

private final static Logger log = LoggerFactory.getLogger(JestHttpClient.class);

Expand Down

0 comments on commit 21ec0bf

Please sign in to comment.