Skip to content

Commit 732741d

Browse files
authored
Build that java api docs from a test (#24354)
We've had `QueryDSLDocumentationTests` for a while but it had a very hopeful comment at the top about how we want to make sure that the example in the query-dsl docs match up with the test but we never had anything that made *sure* that they did. This changes that! Now the examples from the query-dsl docs are all built from the `QueryDSLDocumentationTests`. All except for the percolator example because that is hard to do as it stands now. To make this easier this change moves `QueryDSLDocumentationTests` from core and into the high level rest client. This is useful for two reasons: 1. We expect the high level rest client to be able to use the builders. 2. The code that builds that docs doesn't check out all of Elasticsearch. It only checks out certain directories. Since we're already including snippets from that directory we don't have to make any changes to that process. Closes #24320
1 parent 2f9e946 commit 732741d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+543
-586
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/QueryDSLDocumentationTests.java

Lines changed: 453 additions & 0 deletions
Large diffs are not rendered by default.

core/src/test/java/org/elasticsearch/index/query/QueryDSLDocumentationTests.java

Lines changed: 0 additions & 341 deletions
This file was deleted.

docs/java-api/query-dsl.asciidoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Note that you can easily print (aka debug) JSON generated queries using
1919
The `QueryBuilder` can then be used with any API that accepts a query,
2020
such as `count` and `search`.
2121

22+
:query-dsl-test: {docdir}/../../client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/QueryDSLDocumentationTests.java
23+
2224
include::query-dsl/match-all-query.asciidoc[]
2325

2426
include::query-dsl/full-text-queries.asciidoc[]
@@ -35,4 +37,4 @@ include::query-dsl/special-queries.asciidoc[]
3537

3638
include::query-dsl/span-queries.asciidoc[]
3739

38-
40+
:query-dsl-test!:

docs/java-api/query-dsl/bool-query.asciidoc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,11 @@
33

44
See {ref}/query-dsl-bool-query.html[Bool Query]
55

6-
[source,java]
6+
["source","java",subs="attributes,callouts,macros"]
77
--------------------------------------------------
8-
QueryBuilder qb = boolQuery()
9-
.must(termQuery("content", "test1")) <1>
10-
.must(termQuery("content", "test4")) <1>
11-
.mustNot(termQuery("content", "test2")) <2>
12-
.should(termQuery("content", "test3")) <3>
13-
.filter(termQuery("content", "test5")); <4>
8+
include-tagged::{query-dsl-test}[bool]
149
--------------------------------------------------
1510
<1> must query
1611
<2> must not query
1712
<3> should query
1813
<4> a query that must appear in the matching documents but doesn't contribute to scoring.
19-

docs/java-api/query-dsl/boosting-query.asciidoc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33

44
See {ref}/query-dsl-boosting-query.html[Boosting Query]
55

6-
[source,java]
6+
["source","java",subs="attributes,callouts,macros"]
77
--------------------------------------------------
8-
QueryBuilder qb = boostingQuery(
9-
termQuery("name","kimchy"), <1>
10-
termQuery("name","dadoonet")) <2>
11-
.negativeBoost(0.2f); <3>
8+
include-tagged::{query-dsl-test}[boosting]
129
--------------------------------------------------
1310
<1> query that will promote documents
1411
<2> query that will demote documents
1512
<3> negative boost
16-

0 commit comments

Comments
 (0)