forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to parse sub-aggregations from filter/nested aggregations (…
…opensearch-project#234) * Add support to parse sub-aggregations from filter/nested aggregations Signed-off-by: Abhinav Nath <abhinavnath@ymail.com> * Add USER_GUIDE.md Signed-off-by: Abhinav Nath <abhinavnath@ymail.com> * Add DCO Signed-off-by: Abhinav Nath <abhinavnath@ymail.com> * Add link to USER_GUIDE.md in README.md Signed-off-by: Abhinav Nath <abhinavnath@ymail.com> * Add changelog and changelog verifier (opensearch-project#239) Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com> Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com> Signed-off-by: Abhinav Nath <abhinavnath@ymail.com> * Set javadoc encoding to utf-8 (opensearch-project#50) (opensearch-project#241) Signed-off-by: Meetesh Kumawat<kmeetesh@gmail.com> Signed-off-by: meetesh <kmeetesh@gmail.com> Signed-off-by: Meetesh Kumawat<kmeetesh@gmail.com> Signed-off-by: meetesh <kmeetesh@gmail.com> Signed-off-by: Abhinav Nath <abhinavnath@ymail.com> * Update Jackson Databind to 2.13.4.2 (addressing CVE-2022-42003) (opensearch-project#240) Signed-off-by: Andriy Redko <andriy.redko@aiven.io> Signed-off-by: Andriy Redko <andriy.redko@aiven.io> Signed-off-by: Abhinav Nath <abhinavnath@ymail.com> * Updates changelog for dependabot PRs (opensearch-project#247) * Updates changelog for dependabot PRs Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com> * Adding dependabot label for workflow Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com> Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com> Signed-off-by: Abhinav Nath <abhinavnath@ymail.com> * Update tests to use JUnit's Assert (opensearch-project#244) Signed-off-by: Andriy Redko <andriy.redko@aiven.io> Signed-off-by: Andriy Redko <andriy.redko@aiven.io> Signed-off-by: Abhinav Nath <abhinavnath@ymail.com> * Update literature around changelog (opensearch-project#242) * Update literature Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com> * Removing pr template and updating language Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com> Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com> Co-authored-by: Daniel (dB.) Doubrovkine <dblock@amazon.com> Signed-off-by: Abhinav Nath <abhinavnath@ymail.com> * Bump grgit-gradle from 4.0.1 to 5.0.0 (opensearch-project#243) * Bump grgit-gradle from 4.0.1 to 5.0.0 Bumps [grgit-gradle](https://github.com/ajoberstar/grgit) from 4.0.1 to 5.0.0. - [Release notes](https://github.com/ajoberstar/grgit/releases) - [Commits](ajoberstar/grgit@4.0.1...5.0.0) --- updated-dependencies: - dependency-name: org.ajoberstar.grgit:grgit-gradle dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * Update changelog Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com> Signed-off-by: Abhinav Nath <abhinavnath@ymail.com> * Add DCO Signed-off-by: Abhinav Nath <abhinavnath@ymail.com> * Update CHANGELOG and README Signed-off-by: Abhinav Nath <abhinavnath@ymail.com> * Add DCO Signed-off-by: Abhinav Nath <abhinavnath@ymail.com> * Add DCO Signed-off-by: Abhinav Nath <abhinavnath@ymail.com> * Fix CHANGLOG and README TOC Signed-off-by: Abhinav Nath <abhinavnath@ymail.com> Signed-off-by: Abhinav Nath <abhinavnath@ymail.com> Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com> Signed-off-by: Meetesh Kumawat<kmeetesh@gmail.com> Signed-off-by: meetesh <kmeetesh@gmail.com> Signed-off-by: Andriy Redko <andriy.redko@aiven.io> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com> Co-authored-by: Meetesh Kumawat <kmeetesh@gmail.com> Co-authored-by: Andriy Redko <andriy.redko@aiven.io> Co-authored-by: Daniel (dB.) Doubrovkine <dblock@amazon.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
4a3be6f
commit 1ac790a
Showing
5 changed files
with
214 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# User Guide | ||
|
||
- [User Guide](#user-guide) | ||
- [Sample data](#sample-data) | ||
- [Create an index](#create-an-index) | ||
- [Index data](#index-data) | ||
- [Search for the document](#search-for-the-document) | ||
- [Search documents using a match query](#search-documents-using-a-match-query) | ||
- [Aggregations](#aggregations) | ||
- [Delete the document](#delete-the-document) | ||
- [Delete the index](#delete-the-index) | ||
- [Aggregations](#aggregations) | ||
|
||
## Sample data | ||
|
||
### IndexData class | ||
|
||
```java | ||
static class IndexData { | ||
private String firstName; | ||
private String lastName; | ||
|
||
public IndexData(String firstName, String lastName) { | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
} | ||
|
||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
public void setFirstName(String firstName) { | ||
this.firstName = firstName; | ||
} | ||
|
||
public String getLastName() { | ||
return lastName; | ||
} | ||
|
||
public void setLastName(String lastName) { | ||
this.lastName = lastName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("IndexData{first name='%s', last name='%s'}", firstName, lastName); | ||
} | ||
} | ||
``` | ||
|
||
## Create an index | ||
|
||
```java | ||
String index = "sample-index"; | ||
CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(index).build(); | ||
client.indices().create(createIndexRequest); | ||
``` | ||
|
||
## Index data | ||
|
||
```java | ||
IndexData indexData = new IndexData("John", "Doe"); | ||
IndexRequest<IndexData> indexRequest = new IndexRequest.Builder<IndexData>().index(index).id("1").document(indexData).build(); | ||
client.index(indexRequest); | ||
|
||
indexData = new IndexData("John", "Joe"); | ||
indexRequest = new IndexRequest.Builder<IndexData>().index(index).id("2").document(indexData).build(); | ||
client.index(indexRequest); | ||
``` | ||
|
||
## Search for the documents | ||
|
||
```java | ||
SearchResponse<IndexData> searchResponse = client.search(s -> s.index(index), IndexData.class); | ||
for (int i = 0; i < searchResponse.hits().hits().size(); i++) { | ||
System.out.println(searchResponse.hits().hits().get(i).source()); | ||
} | ||
``` | ||
|
||
## Search documents using a match query | ||
|
||
```java | ||
SearchRequest searchRequest = new SearchRequest.Builder().query(q -> q.match(m -> m.field("firstName") | ||
.query(FieldValue.of("John")))) | ||
.build(); | ||
|
||
SearchResponse<IndexData> searchResponse = client.search(searchRequest, IndexData.class); | ||
for (int i = 0; i < searchResponse.hits().hits().size(); i++) { | ||
System.out.println(searchResponse.hits().hits().get(i).source()); | ||
} | ||
``` | ||
|
||
## Aggregations | ||
|
||
```java | ||
SearchRequest searchRequest = new SearchRequest.Builder().query(q -> q.match(m -> m.field("firstName") | ||
.query(FieldValue.of("John")))) | ||
.aggregations("firstNames", new Aggregation.Builder().terms(t -> t.field("firstName.keyword")) | ||
.build()) | ||
.build(); | ||
|
||
SearchResponse<IndexData> searchResponse = client.search(searchRequest, IndexData.class); | ||
for (Map.Entry<String, Aggregate> entry : searchResponse.aggregations().entrySet()) { | ||
System.out.println("Agg - " + entry.getKey()); | ||
entry.getValue().sterms().buckets().array().forEach(b -> System.out.printf("%s : %d%n", b.key(), b.docCount())); | ||
} | ||
``` | ||
|
||
## Delete the document | ||
|
||
The following sample code deletes a document whose ID is 1. | ||
|
||
```java | ||
client.delete(d -> d.index(index).id("1")); | ||
``` | ||
|
||
## Delete the index | ||
|
||
```java | ||
DeleteIndexRequest deleteIndexRequest = new DeleteRequest.Builder().index(index).build(); | ||
DeleteIndexResponse deleteIndexResponse = client.indices().delete(deleteIndexRequest); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters