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

Deprecate types in count and msearch. #35421

Merged
merged 6 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public CountRequest source(SearchSourceBuilder searchSourceBuilder) {
/**
* The document types to execute the count against. Defaults to be executed against all types.
*
* @deprecated Types are going away, prefer filtering on a type.
* @deprecated Types are in the process of being removed. Instead of using a type, prefer to
* filter on a field on the document.
*/
@Deprecated
public CountRequest types(String... types) {
Expand Down Expand Up @@ -172,6 +173,11 @@ public CountRequest terminateAfter(int terminateAfter) {
return this;
}

/**
* @deprecated Types are in the process of being removed. Instead of using a type, prefer to
* filter on a field on the document.
*/
@Deprecated
public String[] types() {
return Arrays.copyOf(this.types, this.types.length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ public void testSearch() throws Exception {
sourceBuilder.fetchSource(false);
// end::search-source-filtering-off
// tag::search-source-filtering-includes
String[] includeFields = new String[] {"title", "user", "innerObject.*"};
String[] excludeFields = new String[] {"_type"};
String[] includeFields = new String[] {"title", "innerObject.*"};
String[] excludeFields = new String[] {"user"};
sourceBuilder.fetchSource(includeFields, excludeFields);
// end::search-source-filtering-includes
sourceBuilder.fetchSource(true);
Expand Down Expand Up @@ -247,7 +247,6 @@ public void onFailure(Exception e) {
for (SearchHit hit : searchHits) {
// tag::search-hits-singleHit-properties
String index = hit.getIndex();
String type = hit.getType();
String id = hit.getId();
float score = hit.getScore();
// end::search-hits-singleHit-properties
Expand All @@ -263,8 +262,8 @@ public void onFailure(Exception e) {
assertEquals(3, totalHits);
assertNotNull(hits.getHits()[0].getSourceAsString());
assertNotNull(hits.getHits()[0].getSourceAsMap().get("title"));
assertNotNull(hits.getHits()[0].getSourceAsMap().get("user"));
assertNotNull(hits.getHits()[0].getSourceAsMap().get("innerObject"));
assertNull(hits.getHits()[0].getSourceAsMap().get("user"));
}
}

Expand Down Expand Up @@ -1242,18 +1241,6 @@ public void onFailure(Exception e) {

assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
{
// tag::multi-search-request-index
MultiSearchRequest request = new MultiSearchRequest();
request.add(new SearchRequest("posts") // <1>
.types("doc")); // <2>
// end::multi-search-request-index
MultiSearchResponse response = client.msearch(request, RequestOptions.DEFAULT);
MultiSearchResponse.Item firstResponse = response.getResponses()[0];
assertNull(firstResponse.getFailure());
SearchResponse searchResponse = firstResponse.getResponse();
assertEquals(3, searchResponse.getHits().getTotalHits());
}
}

private void indexSearchTestData() throws IOException {
Expand Down Expand Up @@ -1304,19 +1291,12 @@ public void testCount() throws Exception {
// end::count-request-basic
}
{
// tag::count-request-indices-types
CountRequest countRequest = new CountRequest("blog"); // <1>
countRequest.types("doc"); // <2>
// end::count-request-indices-types
// tag::count-request-routing
countRequest.routing("routing"); // <1>
// end::count-request-routing
// tag::count-request-indicesOptions
countRequest.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1>
// end::count-request-indicesOptions
// tag::count-request-preference
countRequest.preference("_local"); // <1>
// end::count-request-preference
// tag::count-request-args
CountRequest countRequest = new CountRequest("blog") // <1>
.routing("routing") // <2>
.indicesOptions(IndicesOptions.lenientExpandOpen()) // <3>
.preference("_local"); // <4>
// end::count-request-args
assertNotNull(client.count(countRequest, RequestOptions.DEFAULT));
}
{
Expand Down
28 changes: 5 additions & 23 deletions docs/java-rest/high-level/search/count.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,16 @@ include-tagged::{doc-tests-file}[{api}-request-basic]
[[java-rest-high-count-request-optional]]
===== Count Request optional arguments

Let's first look at some of the optional arguments of a +{request}+:
A +{request}+ also takes the following optional arguments:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-indices-types]
include-tagged::{doc-tests-file}[{api}-request-args]
--------------------------------------------------
<1> Restricts the request to an index
<2> Limits the request to a type

There are a couple of other interesting optional parameters:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-routing]
--------------------------------------------------
<1> Set a routing parameter

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-indicesOptions]
--------------------------------------------------
<1> Setting `IndicesOptions` controls how unavailable indices are resolved and how wildcard expressions are expanded

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-preference]
--------------------------------------------------
<1> Use the preference parameter e.g. to execute the search to prefer local shards. The default is to randomize across shards.
<2> Set a routing parameter
<3> Setting `IndicesOptions` controls how unavailable indices are resolved and how wildcard expressions are expanded
<4> Use the preference parameter e.g. to execute the search to prefer local shards. The default is to randomize across shards.

===== Using the SearchSourceBuilder in CountRequest

Expand Down
4 changes: 2 additions & 2 deletions docs/java-rest/high-level/search/search.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ be iterated over:
include-tagged::{doc-tests-file}[{api}-hits-singleHit]
--------------------------------------------------

The `SearchHit` provides access to basic information like index, type, docId and
score of each search hit:
The `SearchHit` provides access to basic information like index, document ID
and score of each search hit:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/search/count.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ PUT /twitter/_doc/1?refresh
"user": "kimchy"
}
GET /twitter/_doc/_count?q=user:kimchy
GET /twitter/_count?q=user:kimchy
GET /twitter/_doc/_count
GET /twitter/_count
{
"query" : {
"term" : { "user" : "kimchy" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ setup:
- do:
count:
index: test
type: test
body:
query:
match:
Expand All @@ -29,7 +28,6 @@ setup:
- do:
count:
index: test
type: test
body:
query:
match:
Expand All @@ -43,15 +41,13 @@ setup:
- do:
count:
index: test
type: test
body: { }

- match: {count : 1}

- do:
count:
index: test
type: test

- match: {count : 1}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
setup:
- do:
indices.create:
index: test
- do:
index:
index: test
type: test
id: 1
body: { foo: bar }

- do:
indices.refresh:
index: [test]

---
"count with body":
- do:
count:
index: test
type: test
body:
query:
match:
foo: bar

- match: {count : 1}

- do:
count:
index: test
body:
query:
match:
foo: test

- match: {count : 0}

---
"count with empty body":
# empty body should default to match_all query
- do:
count:
index: test
type: test
body: { }

- match: {count : 1}

- do:
count:
index: test
type: test

- match: {count : 1}

---
"count body without query element":
- do:
catch: bad_request
count:
index: test
type: test
body:
match:
foo: bar
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ setup:
- index: index_3
- query:
match_all: {}
- type: test
- {}
- query:
match_all: {}

Expand Down Expand Up @@ -82,7 +82,7 @@ setup:
- index: index_3
- query:
match_all: {}
- type: test
- {}
- query:
match_all: {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
setup:

- do:
index:
index: index_1
type: test
id: 1
body: { foo: bar }

- do:
index:
index: index_1
type: test
id: 2
body: { foo: baz }

- do:
index:
index: index_1
type: test
id: 3
body: { foo: foo }

- do:
index:
index: index_2
type: test
id: 1
body: { foo: foo }

- do:
indices.refresh: {}

---
"Basic multi-search":

- do:
msearch:
body:
- index: index_*
- query:
match: {foo: foo}
- index: index_2
- query:
match_all: {}
- index: index_1
- query:
match: {foo: foo}
- index: index_3
- query:
match_all: {}
- type: test
- query:
match_all: {}

- match: { responses.0.hits.total: 2 }
- match: { responses.1.hits.total: 1 }
- match: { responses.2.hits.total: 1 }
- match: { responses.3.error.root_cause.0.type: index_not_found_exception }
- match: { responses.3.error.root_cause.0.reason: "/no.such.index/" }
- match: { responses.3.error.root_cause.0.index: index_3 }
- match: { responses.4.hits.total: 4 }

---
"Least impact smoke test":
# only passing these parameters to make sure they are consumed
- do:
msearch:
max_concurrent_shard_requests: 1
max_concurrent_searches: 1
body:
- index: index_*
- query:
match: {foo: foo}
- index: index_2
- query:
match_all: {}
- index: index_1
- query:
match: {foo: foo}
- index: index_3
- query:
match_all: {}
- type: test
- query:
match_all: {}

- match: { responses.0.hits.total: 2 }
- match: { responses.1.hits.total: 1 }
- match: { responses.2.hits.total: 1 }
- match: { responses.3.error.root_cause.0.type: index_not_found_exception }
- match: { responses.3.error.root_cause.0.reason: "/no.such.index/" }
- match: { responses.3.error.root_cause.0.index: index_3 }
- match: { responses.4.hits.total: 4 }
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
import org.elasticsearch.rest.action.ingest.RestPutPipelineAction;
import org.elasticsearch.rest.action.ingest.RestSimulatePipelineAction;
import org.elasticsearch.rest.action.search.RestClearScrollAction;
import org.elasticsearch.rest.action.search.RestCountAction;
import org.elasticsearch.rest.action.search.RestExplainAction;
import org.elasticsearch.rest.action.search.RestMultiSearchAction;
import org.elasticsearch.rest.action.search.RestSearchAction;
Expand Down Expand Up @@ -595,7 +596,7 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
registerHandler.accept(new RestGetSourceAction(settings, restController));
registerHandler.accept(new RestMultiGetAction(settings, restController));
registerHandler.accept(new RestDeleteAction(settings, restController));
registerHandler.accept(new org.elasticsearch.rest.action.document.RestCountAction(settings, restController));
registerHandler.accept(new RestCountAction(settings, restController));
registerHandler.accept(new RestTermVectorsAction(settings, restController));
registerHandler.accept(new RestMultiTermVectorsAction(settings, restController));
registerHandler.accept(new RestBulkAction(settings, restController));
Expand Down
Loading