mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-09 06:25:07 +00:00
4a4e3d70d5
This commit changes the default out-of-the-box configuration for the number of shards from five to one. We think this will help address a common problem of oversharding. For users with time-based indices that need a different default, this can be managed with index templates. For users with non-time-based indices that find they need to re-shard with the split API in place they no longer need to resort only to reindexing. Since this has the impact of changing the default number of shards used in REST tests, we want to ensure that we still have coverage for issues that could arise from multiple shards. As such, we randomize (rarely) the default number of shards in REST tests to two. This is managed via a global index template. However, some tests check the templates that are in the cluster state during the test. Since this template is randomly there, we need a way for tests to skip adding the template used to set the number of shards to two. For this we add the default_shards feature skip. To avoid having to write our docs in a complicated way because sometimes they might be behind one shard, and sometimes they might be behind two shards we apply the default_shards feature skip to all docs tests. That is, these tests will always run with the default number of shards (one).
123 lines
2.9 KiB
Plaintext
123 lines
2.9 KiB
Plaintext
[[query-dsl-terms-set-query]]
|
|
=== Terms Set Query
|
|
|
|
experimental[The terms_set query is a new query and its syntax may change in the future]
|
|
|
|
Returns any documents that match with at least one or more of the
|
|
provided terms. The terms are not analyzed and thus must match exactly.
|
|
The number of terms that must match varies per document and is either
|
|
controlled by a minimum should match field or computed per document in
|
|
a minimum should match script.
|
|
|
|
The field that controls the number of required terms that must match must
|
|
be a number field:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
PUT /my-index
|
|
{
|
|
"mappings": {
|
|
"_doc": {
|
|
"properties": {
|
|
"required_matches": {
|
|
"type": "long"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
PUT /my-index/_doc/1?refresh
|
|
{
|
|
"codes": ["ghi", "jkl"],
|
|
"required_matches": 2
|
|
}
|
|
|
|
PUT /my-index/_doc/2?refresh
|
|
{
|
|
"codes": ["def", "ghi"],
|
|
"required_matches": 2
|
|
}
|
|
--------------------------------------------------
|
|
// CONSOLE
|
|
// TESTSETUP
|
|
|
|
An example that uses the minimum should match field:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
GET /my-index/_search
|
|
{
|
|
"query": {
|
|
"terms_set": {
|
|
"codes" : {
|
|
"terms" : ["abc", "def", "ghi"],
|
|
"minimum_should_match_field": "required_matches"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
// CONSOLE
|
|
|
|
Response:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
{
|
|
"took": 13,
|
|
"timed_out": false,
|
|
"_shards": {
|
|
"total": 1,
|
|
"successful": 1,
|
|
"skipped" : 0,
|
|
"failed": 0
|
|
},
|
|
"hits": {
|
|
"total": 1,
|
|
"max_score": 0.87546873,
|
|
"hits": [
|
|
{
|
|
"_index": "my-index",
|
|
"_type": "_doc",
|
|
"_id": "2",
|
|
"_score": 0.87546873,
|
|
"_source": {
|
|
"codes": ["def", "ghi"],
|
|
"required_matches": 2
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
// TESTRESPONSE[s/"took": 13,/"took": "$body.took",/]
|
|
|
|
Scripts can also be used to control how many terms are required to match
|
|
in a more dynamic way. For example a create date or a popularity field
|
|
can be used as basis for the number of required terms to match.
|
|
|
|
Also the `params.num_terms` parameter is available in the script to indicate the
|
|
number of terms that have been specified.
|
|
|
|
An example that always limits the number of required terms to match to never
|
|
become larger than the number of terms specified:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
GET /my-index/_search
|
|
{
|
|
"query": {
|
|
"terms_set": {
|
|
"codes" : {
|
|
"terms" : ["abc", "def", "ghi"],
|
|
"minimum_should_match_script": {
|
|
"source": "Math.min(params.num_terms, doc['required_matches'].value)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
// CONSOLE
|