Document how copy-to can help speed up queries by querying fewer fields. (#28373)

This commit is contained in:
Adrien Grand 2018-01-31 15:03:54 +01:00 committed by GitHub
parent 9163c9b8d1
commit 89b4485511
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,6 +35,44 @@ several times slower and <<mapping-parent-field,parent-child>> relations can mak
queries hundreds of times slower. So if the same questions can be answered without
joins by denormalizing documents, significant speedups can be expected.
[float]
=== Search as few fields as possible
The more fields a <<query-dsl-query-string-query,`query_string`>> or
<<query-dsl-multi-match-query,`multi_match`>> query targets, the slower it is.
A common technique to improve search speed over multiple fields is to copy
their values into a single field at index time, and then use this field at
search time. This can be automated with the <<copy-to,`copy-to`>> directive of
mappings without having to change the source of documents. Here is an example
of an index containing movies that optimizes queries that search over both the
name and the plot of the movie by indexing both values into the `name_and_plot`
field.
[source,js]
--------------------------------------------------
PUT movies
{
"mappings": {
"_doc": {
"properties": {
"name_and_plot": {
"type": "text"
},
"name": {
"type": "text",
"copy_to": "name_and_plot"
},
"plot": {
"type": "text",
"copy_to": "name_and_plot"
}
}
}
}
}
--------------------------------------------------
// CONSOLE
[float]
=== Pre-index data