Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ferhatsb committed Sep 23, 2012
1 parent 9b8bda2 commit 5135df8
Showing 1 changed file with 72 additions and 4 deletions.
76 changes: 72 additions & 4 deletions README.md
Expand Up @@ -140,14 +140,14 @@ An example of indexing given source to twitter index with type tweet;

``` java
Index index = new Index.Builder(source).index("twitter").type("tweet").build();
client.execute();
client.execute(index);
```

Index id can be typed explicitly;

``` java
Index index = new Index.Builder(source).index("twitter").type("tweet").id("1").build();
client.execute();
client.execute(index);
```

@JestId annotation can be used to mark a property of a bean as id;
Expand Down Expand Up @@ -210,11 +210,79 @@ Result can be cast to List of domain object;

``` java
JestResult result = client.execute(search);
List<Articles> articles = result.getSourceAsObjectList(Article.class);
List<Article> articles = result.getSourceAsObjectList(Article.class);
```

Please refer [ElasticSearch Query DSL](http://www.elasticsearch.org/guide/reference/query-dsl/) documentation to work with complex queries.

### Getting Documents

``` java
Get get = new Get.Builder("1").index("twitter").type("tweet").build();

JestResult result = client.execute(get);
```

Result can be cast to domain object;

``` java
Get get = new Get.Builder("1").index("twitter").type("tweet").build();

JestResult result = client.execute(get);

Article article = result.getSourceAsObject(Article.class);
```

### Updating Documents

```java
String script = "{\n" +
" \"script\" : \"ctx._source.tags += tag\",\n" +
" \"params\" : {\n" +
" \"tag\" : \"blue\"\n" +
" }\n" +
"}";

client.execute(new Update.Builder(script).index("twitter").type("tweet").id("1").build());
```

### Deleting Documents

```java
client.execute(new Delete.Builder("1").index("twitter").type("tweet").build());
```

### Bulk Operations

ElasticSearch's bulk API makes it possible to perform many index/delete operations in a single API call. This can greatly increase the indexing speed.

```java
Bulk bulk = new Bulk("twitter", "tweet");
bulk.addIndex(new Index.Builder(article1).build());
bulk.addIndex(new Index.Builder(article2).build());

bulk.addDelete(new Delete.Builder("1").build());

client.execute(bulk);
```

### Action Parameters

ElasticSearch offers request parameters to set properties like routing, versioning, operation type etc.

For instance you can set "refresh" property to "true" while indexing a document as below;

```java
Index index = new Index.Builder("{\"user\":\"kimchy\"}").index("cvbank").type("candidate").id("1").build();
index.addParameter(Parameters.REFRESH, true);
client.execute(index);
```

### Further Reading

[Integration Tests](https://github.com/searchbox-io/Jest/tree/master/src/test/java/io/searchbox/core) are best place to see things in action.


Contributors
------------
Jest is developed by [@dogukansonmez](https://github.com/dogukansonmez) and [SearchBox.io](http://www.searchbox.io) team.
Expand All @@ -232,4 +300,4 @@ http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
See the License for the specific language governing permissions and limitations under the License.

0 comments on commit 5135df8

Please sign in to comment.