|
13 | 13 | import java.util.Arrays;
|
14 | 14 | import java.util.Date;
|
15 | 15 | import java.util.List;
|
16 |
| -import java.util.stream.Collectors; |
| 16 | +import java.util.logging.Logger; |
| 17 | + |
17 | 18 | import org.elasticsearch.action.DocWriteResponse.Result;
|
18 | 19 | import org.elasticsearch.action.index.IndexResponse;
|
19 | 20 | import org.elasticsearch.action.search.SearchResponse;
|
|
33 | 34 | */
|
34 | 35 | public class ElasticSearchManualIT {
|
35 | 36 |
|
| 37 | + private static final Logger log = Logger.getLogger(ElasticSearchManualIT.class.getName()); |
| 38 | + |
36 | 39 | private static List<Person> listOfPersons = new ArrayList<>() {{
|
37 | 40 | add(new Person(8, "John Woodcraft", new Date()));
|
38 | 41 | add(new Person(10, "John Doe", new Date()));
|
@@ -89,11 +92,26 @@ public void filterByAgeSearch() {
|
89 | 92 | checkSearchResponse(response, 2);
|
90 | 93 | }
|
91 | 94 |
|
92 |
| - private void checkSearchResponse(SearchResponse searchResponse, int expectedSize) { |
| 95 | + /** |
| 96 | + * Trying to search with error in searched name |
| 97 | + */ |
| 98 | + @Test |
| 99 | + public void fuzzySearch() { |
| 100 | + SearchResponse response = client |
| 101 | + .prepareSearch() |
| 102 | + .setQuery(QueryBuilders.fuzzyQuery("fullName", "Sevenson")) |
| 103 | + .get(); |
| 104 | + |
| 105 | + var result = checkSearchResponse(response, 1); |
| 106 | + log.info("Found next persons: " + result); |
| 107 | + } |
| 108 | + |
| 109 | + private List<Person> checkSearchResponse(SearchResponse searchResponse, int expectedSize) { |
93 | 110 | SearchHit[] searchHits = searchResponse.getHits().getHits();
|
94 | 111 | List<Person> result = Arrays.stream(searchHits)
|
95 | 112 | .map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class))
|
96 |
| - .collect(Collectors.toList()); |
| 113 | + .toList(); |
97 | 114 | assertThat("Wrong result items count", result.size(), is(expectedSize));
|
| 115 | + return result; |
98 | 116 | }
|
99 | 117 | }
|
0 commit comments