Skip to content

Commit 4c23349

Browse files
author
Yogesh Gaikwad
committed
Merge branch 'master' into manage-own-api-key-privilege
2 parents af236cc + 6bc38ab commit 4c23349

File tree

63 files changed

+1698
-605
lines changed

Some content is hidden

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

63 files changed

+1698
-605
lines changed

.ci/bwcVersions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ BWC_VERSION:
77
- "7.2.1"
88
- "7.3.0"
99
- "7.3.1"
10+
- "7.3.2"
1011
- "7.4.0"
1112
- "8.0.0"

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.elasticsearch.common.xcontent.XContentBuilder;
4444
import org.elasticsearch.common.xcontent.XContentFactory;
4545
import org.elasticsearch.common.xcontent.XContentType;
46+
import org.elasticsearch.index.query.MatchAllQueryBuilder;
4647
import org.elasticsearch.index.query.MatchQueryBuilder;
4748
import org.elasticsearch.index.query.QueryBuilders;
4849
import org.elasticsearch.index.query.ScriptQueryBuilder;
@@ -81,6 +82,7 @@
8182
import org.elasticsearch.search.suggest.Suggest;
8283
import org.elasticsearch.search.suggest.SuggestBuilder;
8384
import org.elasticsearch.search.suggest.phrase.PhraseSuggestionBuilder;
85+
import org.elasticsearch.xpack.core.index.query.PinnedQueryBuilder;
8486
import org.hamcrest.Matchers;
8587
import org.junit.Before;
8688

@@ -92,7 +94,10 @@
9294
import java.util.Map;
9395

9496
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
97+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFirstHit;
98+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSecondHit;
9599
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertToXContentEquivalent;
100+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasId;
96101
import static org.hamcrest.Matchers.both;
97102
import static org.hamcrest.Matchers.containsString;
98103
import static org.hamcrest.Matchers.either;
@@ -1373,7 +1378,19 @@ public void testCountAllIndicesMatchQuery() throws IOException {
13731378
assertCountHeader(countResponse);
13741379
assertEquals(3, countResponse.getCount());
13751380
}
1376-
1381+
1382+
public void testSearchWithBasicLicensedQuery() throws IOException {
1383+
SearchRequest searchRequest = new SearchRequest("index");
1384+
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
1385+
PinnedQueryBuilder pinnedQuery = new PinnedQueryBuilder(new MatchAllQueryBuilder(), "2", "1");
1386+
searchSourceBuilder.query(pinnedQuery);
1387+
searchRequest.source(searchSourceBuilder);
1388+
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync);
1389+
assertSearchHeader(searchResponse);
1390+
assertFirstHit(searchResponse, hasId("2"));
1391+
assertSecondHit(searchResponse, hasId("1"));
1392+
}
1393+
13771394
private static void assertCountHeader(CountResponse countResponse) {
13781395
assertEquals(0, countResponse.getSkippedShards());
13791396
assertEquals(0, countResponse.getFailedShards());

docs/java-rest/high-level/query-builders.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ This page lists all the available search queries with their corresponding `Query
8383
| {ref}/query-dsl-percolate-query.html[Percolate] | {percolate-ref}/PercolateQueryBuilder.html[PercolateQueryBuilder] |
8484
| {ref}/query-dsl-wrapper-query.html[Wrapper] | {query-ref}/WrapperQueryBuilder.html[WrapperQueryBuilder] | {query-ref}/QueryBuilders.html#wrapperQuery-java.lang.String-[QueryBuilders.wrapperQuery()]
8585
| {ref}/query-dsl-rank-feature-query.html[Rank Feature] | {mapper-extras-ref}/RankFeatureQuery.html[RankFeatureQueryBuilder] |
86+
| {ref}/query-dsl-pinned-query.html[Pinned Query] | The PinnedQueryBuilder is packaged as part of the xpack-core module |
8687
|======
8788

8889
==== Span queries

docs/reference/query-dsl/match-query.asciidoc

Lines changed: 145 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,174 @@
44
<titleabbrev>Match</titleabbrev>
55
++++
66

7+
Returns documents that match a provided text, number, date or boolean value. The
8+
provided text is analyzed before matching.
79

8-
`match` queries accept text/numerics/dates, analyzes
9-
them, and constructs a query. For example:
10+
The `match` query is the standard query for performing a full-text search,
11+
including options for fuzzy matching.
12+
13+
14+
[[match-query-ex-request]]
15+
==== Example request
1016

1117
[source,js]
1218
--------------------------------------------------
1319
GET /_search
1420
{
1521
"query": {
1622
"match" : {
17-
"message" : "this is a test"
23+
"message" : {
24+
"query" : "this is a test"
25+
}
1826
}
1927
}
2028
}
2129
--------------------------------------------------
2230
// CONSOLE
2331

24-
Note, `message` is the name of a field, you can substitute the name of
25-
any field instead.
32+
33+
[[match-top-level-params]]
34+
==== Top-level parameters for `match`
35+
36+
`<field>`::
37+
(Required, object) Field you wish to search.
38+
39+
40+
[[match-field-params]]
41+
==== Parameters for `<field>`
42+
`query`::
43+
+
44+
--
45+
(Required) Text, number, boolean value or date you wish to find in the provided
46+
`<field>`.
47+
48+
The `match` query <<analysis,analyzes>> any provided text before performing a
49+
search. This means the `match` query can search <<text,`text`>> fields for
50+
analyzed tokens rather than an exact term.
51+
--
52+
53+
`analyzer`::
54+
(Optional, string) <<analysis,Analyzer>> used to convert the text in the `query`
55+
value into tokens. Defaults to the <<specify-index-time-analyzer,index-time
56+
analyzer>> mapped for the `<field>`. If no analyzer is mapped, the index's
57+
default analyzer is used.
58+
59+
`auto_generate_synonyms_phrase_query`::
60+
+
61+
--
62+
(Optional, boolean) If `true`, <<query-dsl-match-query-phrase,match phrase>>
63+
queries are automatically created for multi-term synonyms. Defaults to `true`.
64+
65+
See <<query-dsl-match-query-synonyms,Use synonyms with match query>> for an
66+
example.
67+
--
68+
69+
`fuzziness`::
70+
(Optional, string) Maximum edit distance allowed for matching. See <<fuzziness>>
71+
for valid values and more information. See <<query-dsl-match-query-fuzziness>>
72+
for an example.
73+
74+
`max_expansions`::
75+
(Optional, integer) Maximum number of terms to which the query will
76+
expand. Defaults to `50`.
77+
78+
`prefix_length`::
79+
(Optional, integer) Number of beginning characters left unchanged for fuzzy
80+
matching. Defaults to `0`.
81+
82+
`transpositions`::
83+
(Optional, boolean) If `true`, edits for fuzzy matching include
84+
transpositions of two adjacent characters (ab → ba). Defaults to `true`.
85+
86+
`fuzzy_rewrite`::
87+
+
88+
--
89+
(Optional, string) Method used to rewrite the query. See the
90+
<<query-dsl-multi-term-rewrite, `rewrite` parameter>> for valid values and more
91+
information.
92+
93+
If the `fuzziness` parameter is not `0`, the `match` query uses a `rewrite`
94+
method of `top_terms_blended_freqs_${max_expansions}` by default.
95+
--
96+
97+
`lenient`::
98+
(Optional, boolean) If `true`, format-based errors, such as providing a text
99+
`query` value for a <<number,numeric>> field, are ignored. Defaults to `false`.
100+
101+
`operator`::
102+
+
103+
--
104+
(Optional, string) Boolean logic used to interpret text in the `query` value.
105+
Valid values are:
106+
107+
`OR` (Default)::
108+
For example, a `query` value of `capital of Hungary` is interpreted as `capital
109+
OR of OR Hungary`.
110+
111+
`AND`::
112+
For example, a `query` value of `capital of Hungary` is interpreted as `capital
113+
AND of AND Hungary`.
114+
--
115+
116+
`minimum_should_match`::
117+
+
118+
--
119+
(Optional, string) Minimum number of clauses that must match for a document to
120+
be returned. See the <<query-dsl-minimum-should-match, `minimum_should_match`
121+
parameter>> for valid values and more information.
122+
--
123+
124+
`zero_terms_query`::
125+
+
126+
--
127+
(Optional, string) Indicates whether no documents are returned if the `analyzer`
128+
removes all tokens, such as when using a `stop` filter. Valid values are:
129+
130+
`none` (Default)::
131+
No documents are returned if the `analyzer` removes all tokens.
132+
133+
`all`::
134+
Returns all documents, similar to a <<query-dsl-match-all-query,`match_all`>>
135+
query.
136+
137+
See <<query-dsl-match-query-zero>> for an example.
138+
--
139+
140+
141+
[[match-query-notes]]
142+
==== Notes
143+
144+
[[query-dsl-match-query-short-ex]]
145+
===== Short request example
146+
147+
You can simplify the match query syntax by combining the `<field>` and `query`
148+
parameters. For example:
149+
150+
[source,js]
151+
----
152+
GET /_search
153+
{
154+
"query": {
155+
"match" : {
156+
"message" : "this is a test"
157+
}
158+
}
159+
}
160+
----
161+
// CONSOLE
26162

27163
[[query-dsl-match-query-boolean]]
28-
==== match
164+
===== How the match query works
29165

30166
The `match` query is of type `boolean`. It means that the text
31167
provided is analyzed and the analysis process constructs a boolean query
32-
from the provided text. The `operator` flag can be set to `or` or `and`
168+
from the provided text. The `operator` parameter can be set to `or` or `and`
33169
to control the boolean clauses (defaults to `or`). The minimum number of
34170
optional `should` clauses to match can be set using the
35171
<<query-dsl-minimum-should-match,`minimum_should_match`>>
36172
parameter.
37173

38-
Here is an example when providing additional parameters (note the slight
39-
change in structure, `message` is the field name):
174+
Here is an example with the `operator` parameter:
40175

41176
[source,js]
42177
--------------------------------------------------
@@ -63,7 +198,7 @@ data-type mismatches, such as trying to query a numeric field with a text
63198
query string. Defaults to `false`.
64199

65200
[[query-dsl-match-query-fuzziness]]
66-
===== Fuzziness
201+
===== Fuzziness in the match query
67202

68203
`fuzziness` allows _fuzzy matching_ based on the type of field being queried.
69204
See <<fuzziness>> for allowed settings.

docs/reference/scripting/using.asciidoc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,21 @@ DELETE _scripts/calculate-score
195195
// CONSOLE
196196
// TEST[continued]
197197

198+
[float]
199+
[[modules-scripting-search-templates]]
200+
=== Search templates
201+
You can also use the `_scripts` API to store **search templates**. Search
202+
templates save specific <<search-search,search requests>> with placeholder
203+
values, called template parameters.
204+
205+
You can use stored search templates to run searches without writing out the
206+
entire query. Just provide the stored template's ID and the template parameters.
207+
This is useful when you want to run a commonly used query quickly and without
208+
mistakes.
209+
210+
Search templates use the http://mustache.github.io/mustache.5.html[mustache
211+
templating language]. See <<search-template>> for more information and examples.
212+
198213
[float]
199214
[[modules-scripting-using-caching]]
200215
=== Script caching

0 commit comments

Comments
 (0)