|
18 | 18 |
|
19 | 19 | import co.elastic.clients.elasticsearch.ElasticsearchClient; |
20 | 20 | import co.elastic.clients.elasticsearch._types.SortOrder; |
21 | | -import co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery; |
22 | | -import co.elastic.clients.elasticsearch._types.query_dsl.MatchQuery; |
23 | | -import co.elastic.clients.elasticsearch._types.query_dsl.Query; |
24 | 21 | import co.elastic.clients.elasticsearch.core.SearchRequest; |
25 | 22 | import co.elastic.clients.elasticsearch.core.SearchResponse; |
26 | 23 | import org.eclipse.jnosql.communication.document.Document; |
|
30 | 27 |
|
31 | 28 | import java.io.IOException; |
32 | 29 | import java.util.HashMap; |
33 | | -import java.util.List; |
34 | 30 | import java.util.Map; |
35 | 31 | import java.util.function.Consumer; |
36 | 32 | import java.util.stream.Stream; |
@@ -59,18 +55,14 @@ static Map<String, Object> getMap(DocumentEntity entity) { |
59 | 55 | } |
60 | 56 |
|
61 | 57 | static Stream<DocumentEntity> query(DocumentQuery query, ElasticsearchClient client, String index) { |
62 | | - QueryConverterResult select = QueryConverter.select(query); |
| 58 | + QueryConverterResult select = QueryConverter.select(client, index, query); |
63 | 59 |
|
64 | 60 | try { |
65 | | - Stream<DocumentEntity> idQueryStream = Stream.empty(); |
66 | 61 | Stream<DocumentEntity> statementQueryStream = Stream.empty(); |
67 | | - if (select.hasId()) { |
68 | | - idQueryStream = executeId(client, index, select); |
69 | | - } |
70 | 62 | if (select.hasStatement()) { |
71 | 63 | statementQueryStream = executeStatement(query, client, index, select); |
72 | 64 | } |
73 | | - return Stream.concat(idQueryStream, statementQueryStream).distinct(); |
| 65 | + return statementQueryStream.distinct(); |
74 | 66 | } catch (IOException e) { |
75 | 67 | throw new ElasticsearchException("An error to execute a query on elasticsearch", e); |
76 | 68 | } |
@@ -122,25 +114,6 @@ private static boolean isSudDocumentList(Object value) { |
122 | 114 | allMatch(d -> d instanceof Iterable && isSudDocument(d)); |
123 | 115 | } |
124 | 116 |
|
125 | | - private static Stream<DocumentEntity> executeId(ElasticsearchClient client, String index, |
126 | | - QueryConverterResult select) throws IOException { |
127 | | - |
128 | | - List<Query> ids = select.getIds().stream() |
129 | | - .map(id -> MatchQuery.of(m -> m |
130 | | - .field(EntityConverter.ID_FIELD) |
131 | | - .query(id))._toQuery() |
132 | | - ).collect(toList()); |
133 | | - |
134 | | - SearchRequest searchRequest = SearchRequest.of(sb -> sb |
135 | | - .index(index) |
136 | | - .query(BoolQuery.of(q -> q |
137 | | - .should(ids))._toQuery())); |
138 | | - SearchResponse<Map> responses = client.search(searchRequest, Map.class); |
139 | | - |
140 | | - return getDocumentEntityStream(client, responses); |
141 | | - |
142 | | - } |
143 | | - |
144 | 117 | static Stream<DocumentEntity> getDocumentEntityStream(ElasticsearchClient client, SearchResponse<Map> responses) { |
145 | 118 | return responses.hits().hits().stream() |
146 | 119 | .map(hits -> ElasticsearchEntry.of(hits.id(), hits.source())) |
|
0 commit comments