mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-13 08:25:26 +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.
114 lines
2.8 KiB
Plaintext
114 lines
2.8 KiB
Plaintext
[[query-dsl-exists-query]]
|
|
=== Exists Query
|
|
|
|
Returns documents that have at least one non-`null` value in the original field:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
GET /_search
|
|
{
|
|
"query": {
|
|
"exists" : { "field" : "user" }
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
// CONSOLE
|
|
|
|
For instance, these documents would all match the above query:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
{ "user": "jane" }
|
|
{ "user": "" } <1>
|
|
{ "user": "-" } <2>
|
|
{ "user": ["jane"] }
|
|
{ "user": ["jane", null ] } <3>
|
|
--------------------------------------------------
|
|
// NOTCONSOLE
|
|
<1> An empty string is a non-`null` value.
|
|
<2> Even though the `standard` analyzer would emit zero tokens, the original field is non-`null`.
|
|
<3> At least one non-`null` value is required.
|
|
|
|
These documents would *not* match the above query:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
{ "user": null }
|
|
{ "user": [] } <1>
|
|
{ "user": [null] } <2>
|
|
{ "foo": "bar" } <3>
|
|
--------------------------------------------------
|
|
// NOTCONSOLE
|
|
<1> This field has no values.
|
|
<2> At least one non-`null` value is required.
|
|
<3> The `user` field is missing completely.
|
|
|
|
[float]
|
|
==== `null_value` mapping
|
|
|
|
If the field mapping includes the <<null-value,`null_value`>> setting
|
|
then explicit `null` values are replaced with the specified `null_value`. For
|
|
instance, if the `user` field were mapped as follows:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
PUT /example?include_type_name=true
|
|
{
|
|
"mappings": {
|
|
"_doc": {
|
|
"properties": {
|
|
"user": {
|
|
"type": "keyword",
|
|
"null_value": "_null_"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
// CONSOLE
|
|
|
|
then explicit `null` values would be indexed as the string `_null_`, and the
|
|
following docs would match the `exists` filter:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
{ "user": null }
|
|
{ "user": [null] }
|
|
--------------------------------------------------
|
|
// NOTCONSOLE
|
|
|
|
However, these docs--without explicit `null` values--would still have
|
|
no values in the `user` field and thus would not match the `exists` filter:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
{ "user": [] }
|
|
{ "foo": "bar" }
|
|
--------------------------------------------------
|
|
// NOTCONSOLE
|
|
|
|
==== `missing` query
|
|
|
|
There isn't a `missing` query. Instead use the `exists` query inside a
|
|
`must_not` clause as follows:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
GET /_search
|
|
{
|
|
"query": {
|
|
"bool": {
|
|
"must_not": {
|
|
"exists": {
|
|
"field": "user"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
// CONSOLE
|
|
|
|
This query returns documents that have no value in the user field.
|