-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add document _count API support to Rest High Level Client. #34267
Conversation
Add `count()` api method, `CountRequest` and `CountResponse` classes to HLRC. Code in server module is unchanged. Relates to elastic#27205
Pinging @elastic/es-core-infra |
can you move the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work so far. We caught you in the middle of some major changes, like the documentation change, so lets clean those up and then ill fire off the CI service against it. <3
@@ -749,6 +751,29 @@ public final void indexAsync(IndexRequest indexRequest, RequestOptions options, | |||
emptySet()); | |||
} | |||
|
|||
/** | |||
* Executes a count request using the Count API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We typically add a webpage to these javadocs. See others for examples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed, let me know what you think.
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not need toXContent in responses. This will affect your tests, and you can look at #33921 for a good example on how to structure the tests. A lot has been in flux, recently :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed, let me know what you think. XContentTester is quite useful!
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see other msg about the toXContent in responses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
public class CountIT extends ESRestHighLevelClientTestCase { | ||
|
||
@Before | ||
public void indexDocuments() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this can go in the existing SearchIT, i would imagine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to SearchIT
import static org.elasticsearch.test.EqualsHashCodeTestUtils.checkEqualsAndHashCode; | ||
|
||
//quite similar to SearchRequestTests as CountRequest wraps SearchRequest | ||
public class CountRequestTests extends ESTestCase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets move these in the same place as the request/response above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> RequestConverters.bulk(bulkRequest)); | ||
assertEquals( | ||
"Mismatching content-type found for request with content-type [SMILE], " + "previous requests have content-type [JSON]", | ||
exception.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls dont mess with the existing spacing on this class, its causing a big diff :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhm yes, this should be reverted now
@@ -648,7 +648,6 @@ public void testApiNamingConventions() throws Exception { | |||
//this list should be empty once the high-level client is feature complete | |||
String[] notYetSupportedApi = new String[]{ | |||
"cluster.remote_info", | |||
"count", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[[java-rest-high-count]] | ||
=== Count API | ||
|
||
[[java-rest-high-document-count-request]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have very recently changed how we do these docs. Its much simpler now without a lot of copy/pasta. #34157 is a good example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Changed the docs
Thanks for comments @hub-cap - I'm addressing these, can you please clarify
Do you reffer to |
OK, I get it, I will create |
- move CountRequest and CountResponse into org.elasticsearch.client.core - remove ToXContent in CountResponse and use XContentTester in tests - remove CountIT and CountDocumentationIT classes, add the tests into SearchIT and SearchDocumentationIT - use new markdown and structure in count.asciidoc docs - add javadocs in RestHighLevelClient and revert existing spacing in RestHighLevelClientTests
Hi @hub-cap, I've addressed changes you've requested. Let me know what you think. Yeah, I see there are some changes going on, this way at least it keeps me in the loop :D, and the XContentTester is useful. |
Yes there is much in flight now. im having a look at your PR now :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good. Lets clean up the little nits I mentioned and see if the magic incantations of the tests work.
@@ -485,9 +485,9 @@ public void testRethrottle() { | |||
List<Tuple<String, Supplier<Request>>> variants = new ArrayList<>(); | |||
variants.add(new Tuple<String, Supplier<Request>>("_reindex", () -> RequestConverters.rethrottleReindex(rethrottleRequest))); | |||
variants.add(new Tuple<String, Supplier<Request>>("_update_by_query", | |||
() -> RequestConverters.rethrottleUpdateByQuery(rethrottleRequest))); | |||
() -> RequestConverters.rethrottleUpdateByQuery(rethrottleRequest))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a lot of these space altered in this RequestConvertersTests.java
class. Can you revert them as we dont need to alter them. Curse you, but I love you, IDE!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
think it should be ok, please check https://github.com/elastic/elasticsearch/compare/master...mrdjen:hl_client_count_api-review#diff-dd0dd6a857a14996c88dd7820d6f8c7c
@@ -1233,4 +1235,71 @@ private static void assertSearchHeader(SearchResponse searchResponse) { | |||
assertEquals(0, searchResponse.getShardFailures().length); | |||
assertEquals(SearchResponse.Clusters.EMPTY, searchResponse.getClusters()); | |||
} | |||
|
|||
//Count API IT tests start |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you dont need these, its a big ole file but we dont do it with other sections
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, removed
add to whitelist |
Once the nits are addressed please also merge in the latest from master one more time like you've done before. It will be the best way to ensure the tests pass :) Ill take care of backporting it once its merged. Thanks again for all the work you put in to this! |
- remove comments in SearchIT
Hi @hub-cap I've addressed the nits you've requested, |
Add `count()` api method, `CountRequest` and `CountResponse` classes to HLRC. Code in server module is unchanged. Relates to #27205
Code is merged and backported to 6.x. thanks much for the contribution! Sorry it took so long!!! :D |
Hey great @hub-cap! |
Add
count()
api method,CountRequest
andCountResponse
classes to HLRC. Code in server module is unchanged.Relates to #27205