[BUG] Azure Cog Search - Skip Parameter Error when not using Skip Feature
Describe the bug
When I am using com.azure.search.documents.SearchClient#search(java.lang.String, com.azure.search.documents.models.SearchOptions, com.azure.core.util.Context) in version 11.6.0-beta.10 using the only the setFilter and setSelect Search options I get an exception during the hasNext call at the 100k document
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: com.azure.core.exception.HttpResponseException: Status code 400, "{"error":{"code":"InvalidRequestParameter","message":"Value must be between 0 and 100000.\r
Parameter name: $skip","details":[{"code":"ParameterValueOutOfRange","message":"Value must be between 0 and 100000."}]}}"] with root cause
Exception or Stack Trace Stack Trace
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: com.azure.core.exception.HttpResponseException: Status code 400, "{"error":{"code":"InvalidRequestParameter","message":"Value must be between 0 and 100000.\r
Parameter name: $skip","details":[{"code":"ParameterValueOutOfRange","message":"Value must be between 0 and 100000."}]}}"] with root cause
java.lang.IllegalStateException: Missing required property/properties: message
at com.azure.search.documents.implementation.models.SearchError.lambda$fromJson$2(SearchError.java:125)
at com.azure.json.JsonReader.readMapOrObject(JsonReader.java:551)
at com.azure.json.JsonReader.readObject(JsonReader.java:455)
at com.azure.search.documents.implementation.models.SearchError.fromJson(SearchError.java:91)
at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(Unknown Source)
at com.azure.core.implementation.MethodHandleReflectiveInvoker.invokeStatic(MethodHandleReflectiveInvoker.java:26)
at com.azure.core.implementation.ReflectionSerializable.deserializeAsJsonSerializable(ReflectionSerializable.java:194)
at com.azure.core.implementation.serializer.HttpResponseBodyDecoder.deserialize(HttpResponseBodyDecoder.java:169)
at com.azure.core.implementation.serializer.HttpResponseBodyDecoder.deserializeBody(HttpResponseBodyDecoder.java:150)
at com.azure.core.implementation.serializer.HttpResponseBodyDecoder.decodeByteArray(HttpResponseBodyDecoder.java:67)
at com.azure.core.implementation.serializer.HttpResponseDecoder$HttpDecodedResponse.getDecodedBody(HttpResponseDecoder.java:93)
at com.azure.core.implementation.http.rest.SyncRestProxy.ensureExpectedStatus(SyncRestProxy.java:127)
at com.azure.core.implementation.http.rest.SyncRestProxy.handleRestReturnType(SyncRestProxy.java:206)
at com.azure.core.implementation.http.rest.SyncRestProxy.invoke(SyncRestProxy.java:82)
at com.azure.core.implementation.http.rest.RestProxyBase.invoke(RestProxyBase.java:128)
at com.azure.core.http.rest.RestProxy.invoke(RestProxy.java:97)
at jdk.proxy3/jdk.proxy3.$Proxy245.searchPostSync(Unknown Source)
at com.azure.search.documents.implementation.DocumentsImpl.searchPostWithResponse(DocumentsImpl.java:631)
at com.azure.search.documents.SearchClient.lambda$search$4(SearchClient.java:808)
at com.azure.search.documents.implementation.util.Utility.executeRestCallWithExceptionHandling(Utility.java:192)
at com.azure.search.documents.SearchClient.search(SearchClient.java:807)
at com.azure.search.documents.SearchClient.lambda$search$2(SearchClient.java:794)
at com.azure.search.documents.util.SearchPagedIterable.lambda$new$0(SearchPagedIterable.java:64)
at com.azure.core.util.paging.ContinuablePagedByIteratorBase.requestPage(ContinuablePagedByIteratorBase.java:104)
at com.azure.core.util.paging.ContinuablePagedByIteratorBase.hasNext(ContinuablePagedByIteratorBase.java:65)
at java.base/java.util.Iterator.forEachRemaining(Unknown Source)
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Unknown Source)
at java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.base/java.util.stream.AbstractPipeline.evaluateToArrayNode(Unknown Source)
at java.base/java.util.stream.ReferencePipeline.toArray(Unknown Source)
at java.base/java.util.stream.ReferencePipeline.toArray(Unknown Source)
at java.base/java.util.stream.ReferencePipeline.toList(Unknown Source)
at org.vena.aichat.service.search.DocumentQueryService.search(DocumentQueryService.java:80)
To Reproduce
Steps to reproduce the behavior:
Create Search Index with over 100k Documents, Read them in Java using only the setSelect and setFilter search options. You can reproduce this using stream and toList or you can iterate through using next() and hasNext()
Code Snippet
SearchOptions options = new SearchOptions().setFilter(filter).setSelect(selectedFields.stream().toArray(String[]::new));
SearchPagedIterable searchResults = searchClient.search("*", options, Context.NONE);
searchResults.stream().map(result -> result.getDocument(clazz)).toList();
Search client created like
SearchClientBuilder builder = new SearchClientBuilder()
.endpoint(settings.baseURL())
.indexName(indexName).credential(identitySettings.getCredential());
return builder.buildClient();
Expected behavior To be able to read more than 100 thousand documents from cognitive search when not using the skip feature.
Screenshots If applicable, add screenshots to help explain your problem.
Setup (please complete the following information):
- OS: iOS and ECS container
- IDE: IntelliJ
- Library/Libraries: azure-search-documents-11.6.0-beta.10.jar
- Java version: 17
- App Server/Environment:
- Frameworks: Spring Boot
Additional context
Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- [x ] Bug Description Added
- [x ] Repro Steps Added
- [x ] Setup information Added
@alzimmermsft @jairmyree
Thank you for your feedback. Tagging and routing to the team member best able to assist.
Hi @camilla11, thank you for filing this issue.
Unfortunately for the SDKs, this is a behavior on the service side:
https://learn.microsoft.com/azure/search/search-pagination-page-layout#paging-through-a-large-number-of-results
Where paging results is determined by $top (limited to 1000 at the time of writing this comment) and $skip (limited to 100,000 at the time of writing this comment). If $skip is larger that 100,000 the service will return an exception as you're seeing. The SDK doesn't prevent this in case the service change behavior in the future, such as allowing more than 100,000 to be used in $skip.
The link shows methods on how to get around this limitation by using sort ordering and filtering, which resulting in cases where you'll need to perform multiple queries to iterate through more than 100,000 results where each query is a unique range of documents in the service.
Hi @camilla11. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.
Thank you!
@alzimmermsft Is it possible to delete more than 100k documents at a time? When iterating through documents and deleting every batch of 1000, after a delete of a batch, the next() in ContinuablePagedByItemIterable returned by SearchPagedIterable search(String searchText, SearchOptions searchOptions, Context context) sometimes skips 1000 results.