Browse Source

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

Adrien Grand 7 years ago
parent
commit
89b4485511
1 changed files with 38 additions and 0 deletions
  1. 38 0
      docs/reference/how-to/search-speed.asciidoc

+ 38 - 0
docs/reference/how-to/search-speed.asciidoc

@@ -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