mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-11 07:25:23 +00:00
* Default include_type_name to false for get and put mappings. * Default include_type_name to false for get field mappings. * Add a constant for the default include_type_name value. * Default include_type_name to false for get and put index templates. * Default include_type_name to false for create index. * Update create index calls in REST documentation to use include_type_name=true. * Some minor clean-ups around the get index API. * In REST tests, use include_type_name=true by default for index creation. * Make sure to use 'expression == false'. * Clarify the different IndexTemplateMetaData toXContent methods. * Fix FullClusterRestartIT#testSnapshotRestore. * Fix the ml_anomalies_default_mappings test. * Fix GetFieldMappingsResponseTests and GetIndexTemplateResponseTests. We make sure to specify include_type_name=true during xContent parsing, so we continue to test the legacy typed responses. XContent generation for the typeless responses is currently only covered by REST tests, but we will be adding unit test coverage for these as we implement each typeless API in the Java HLRC. This commit also refactors GetMappingsResponse to follow the same appraoch as the other mappings-related responses, where we read include_type_name out of the xContent params, instead of creating a second toXContent method. This gives better consistency in the response parsing code. * Fix more REST tests. * Improve some wording in the create index documentation. * Add a note about types removal in the create index docs. * Fix SmokeTestMonitoringWithSecurityIT#testHTTPExporterWithSSL. * Make sure to mention include_type_name in the REST docs for affected APIs. * Make sure to use 'expression == false' in FullClusterRestartIT. * Mention include_type_name in the REST templates docs.
124 lines
2.9 KiB
Plaintext
124 lines
2.9 KiB
Plaintext
[[query-dsl-terms-set-query]]
|
|
=== Terms Set Query
|
|
|
|
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?include_type_name=true
|
|
{
|
|
"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" : {
|
|
"value": 1,
|
|
"relation": "eq"
|
|
},
|
|
"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
|