SearchBuilder implements Builder<Search> { @Override public Search build() { return new Search(filter.stream().map(ConditionBuilder::build).collect(toList()), query.stream().map(ConditionBuilder::build).collect(toList()), sort.stream().map(SortFieldBuilder::build).collect(toList()), paging == null ? null : IndexPagingState.fromByteBuffer(ByteBufferUtils.byteBuffer(paging)), refresh); } SearchBuilder(); SearchBuilder filter(ConditionBuilder<?, ?>... builders); SearchBuilder query(ConditionBuilder<?, ?>... builders); SearchBuilder sort(SortFieldBuilder... builders); SearchBuilder refresh(boolean refresh); SearchBuilder paging(IndexPagingState pagingState); @Override Search build(); String toJson(); static SearchBuilder fromJson(String json);  }
@Test public void testBuild() throws IOException { ConditionBuilder<?, ?> filter = match("field1", "value2"); ConditionBuilder<?, ?> query = match("field2", "value2"); SimpleSortFieldBuilder sort1 = field("field3"); SimpleSortFieldBuilder sort2 = field("field4"); SearchBuilder builder = new SearchBuilder().filter(filter) .query(query) .sort(sort1, sort2); String json = builder.toJson(); assertEquals("JSON serialization is wrong", json, JsonSerializer.toString(builder)); }