11package org .typesense .api ;
22
3+ import static org .hamcrest .MatcherAssert .assertThat ;
4+ import static org .hamcrest .Matchers .is ;
5+ import static org .junit .jupiter .api .Assertions .assertEquals ;
6+ import static org .junit .jupiter .api .Assertions .assertFalse ;
7+ import static org .junit .jupiter .api .Assertions .fail ;
8+
9+ import java .util .ArrayList ;
10+ import java .util .HashMap ;
11+ import java .util .List ;
12+ import java .util .Map ;
313import org .junit .jupiter .api .BeforeEach ;
414import org .junit .jupiter .api .Test ;
515import org .typesense .api .exceptions .ObjectNotFound ;
1020import org .typesense .model .ImportDocumentsParameters ;
1121import org .typesense .model .SearchParameters ;
1222import org .typesense .model .SearchResult ;
13-
14- import java .util .ArrayList ;
15- import java .util .EmptyStackException ;
16- import java .util .HashMap ;
17- import java .util .List ;
18- import java .util .Map ;
19-
20- import static org .junit .jupiter .api .Assertions .assertEquals ;
21- import static org .junit .jupiter .api .Assertions .assertFalse ;
22- import static org .junit .jupiter .api .Assertions .fail ;
23+ import org .typesense .model .UpdateDocumentsParameters ;
2324
2425class DocumentsTest {
2526
@@ -263,4 +264,20 @@ void testNestedObjectImport() throws Exception {
263264 assertEquals (1 , searchResult .getFound ().intValue ());
264265 assertEquals (1 , searchResult .getHits ().size ());
265266 }
266- }
267+
268+ @ Test
269+ void testUpdateDocumentsByQuery () throws Exception {
270+ helper .createTestDocument ();
271+
272+ UpdateDocumentsParameters updateDocumentsParameters = new UpdateDocumentsParameters ()
273+ .filterBy ("publication_year:1666" );
274+ Map <String , Object > fieldToAdd = new HashMap <>();
275+ fieldToAdd .put ("ratings_count" , "200" );
276+ Map <String , Integer > response = client .collections ("books" ).documents ().update (fieldToAdd , updateDocumentsParameters );
277+ assertThat (response .get ("num_updated" ), is (1 ));
278+
279+ // try fetching the document back
280+ Map <String , Object > resp = client .collections ("books" ).documents ("1" ).retrieve ();
281+ assertThat (resp .get ("ratings_count" ), is (200 ));
282+ }
283+ }
0 commit comments