Skip to content
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

Merged
merged 6 commits into from
Nov 2, 2018

Conversation

mrdjen
Copy link
Contributor

@mrdjen mrdjen commented Oct 3, 2018

Add count() api method, CountRequest and CountResponse classes to HLRC. Code in server module is unchanged.

Relates to #27205

Add `count()` api method, `CountRequest` and `CountResponse` classes to HLRC. Code in server module is unchanged.

Relates to elastic#27205
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@hub-cap
Copy link
Contributor

hub-cap commented Oct 3, 2018

can you move the count package to core? Ive told a few people to drop the core (things like search, count, etc..) into the core package. None of those PRs have landed yet, so just create it in your PR. im reviewing it now, but i just wanted to ping you with this info so i dont forget :P

Copy link
Contributor

@hub-cap hub-cap left a 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
Copy link
Contributor

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

Copy link
Contributor Author

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 {
Copy link
Contributor

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

Copy link
Contributor Author

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 {
Copy link
Contributor

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

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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());
Copy link
Contributor

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 :)

Copy link
Contributor Author

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",
Copy link
Contributor

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]]
Copy link
Contributor

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

Copy link
Contributor Author

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

@mrdjen
Copy link
Contributor Author

mrdjen commented Oct 4, 2018

Thanks for comments @hub-cap - I'm addressing these, can you please clarify

can you move the count package to core

Do you reffer to org.elasticsearch.client package in rest-high-level or shoud I create core and move the count package there? (As I don't see core)

@mrdjen
Copy link
Contributor Author

mrdjen commented Oct 4, 2018

OK, I get it, I will create core package

- 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
@mrdjen
Copy link
Contributor Author

mrdjen commented Oct 9, 2018

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.

@hub-cap
Copy link
Contributor

hub-cap commented Oct 15, 2018

Yes there is much in flight now. im having a look at your PR now :)

Copy link
Contributor

@hub-cap hub-cap left a 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)));
Copy link
Contributor

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!

Copy link
Contributor Author

@mrdjen mrdjen Oct 17, 2018

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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, removed

@hub-cap
Copy link
Contributor

hub-cap commented Oct 15, 2018

add to whitelist

@hub-cap
Copy link
Contributor

hub-cap commented Oct 15, 2018

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!

@mrdjen
Copy link
Contributor Author

mrdjen commented Oct 17, 2018

Hi @hub-cap I've addressed the nits you've requested,
Thanks

@hub-cap hub-cap self-assigned this Oct 22, 2018
@colings86 colings86 added v6.6.0 and removed v6.5.0 labels Oct 25, 2018
@hub-cap hub-cap merged commit 34677b9 into elastic:master Nov 2, 2018
hub-cap pushed a commit that referenced this pull request Nov 2, 2018
Add `count()` api method, `CountRequest` and `CountResponse` classes to HLRC. Code in server module is unchanged.

Relates to #27205
@hub-cap
Copy link
Contributor

hub-cap commented Nov 2, 2018

Code is merged and backported to 6.x. thanks much for the contribution! Sorry it took so long!!! :D

@mrdjen
Copy link
Contributor Author

mrdjen commented Nov 2, 2018

Hey great @hub-cap!
Np, I'm glad to contribute back!
Thank you as well and hope to contribute sometime again in the future :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants