|
| 1 | +[[query-dsl-text-expansion-query]] |
| 2 | +== Text expansion query |
| 3 | +++++ |
| 4 | +<titleabbrev>Text expansion</titleabbrev> |
| 5 | +++++ |
| 6 | + |
| 7 | +The text expansion query uses a {nlp} model to convert the query text into a |
| 8 | +list of token-weight pairs which are then used in a query against a |
| 9 | +<<rank-features,rank features field>>. |
| 10 | + |
| 11 | +[discrete] |
| 12 | +[[text-expansion-query-ex-request]] |
| 13 | +=== Example request |
| 14 | + |
| 15 | + |
| 16 | +[source,console] |
| 17 | +---- |
| 18 | +GET _search |
| 19 | +{ |
| 20 | + "query":{ |
| 21 | + "text_expansion":{ |
| 22 | + "<rank_features_field>":{ |
| 23 | + "model_id":"the model to produce the token weights", |
| 24 | + "model_text":"the query string" |
| 25 | + } |
| 26 | + } |
| 27 | + } |
| 28 | +} |
| 29 | +---- |
| 30 | +// TEST[skip: TBD] |
| 31 | + |
| 32 | +[discrete] |
| 33 | +[[text-expansion-query-params]] |
| 34 | +=== Top level parameters for `text_expansion` |
| 35 | + |
| 36 | +`<rank_features_field>`::: |
| 37 | +(Required, object) |
| 38 | +The name of the field that contains the token-weight pairs the NLP model created |
| 39 | +based on the input text. |
| 40 | + |
| 41 | +[discrete] |
| 42 | +[[text-expansion-rank-feature-field-params]] |
| 43 | +=== Top level parameters for `<rank_features_field>` |
| 44 | + |
| 45 | +`model_id`:::: |
| 46 | +(Required, string) |
| 47 | +The ID of the model to use to convert the query text into token-weight pairs. It |
| 48 | +must be the same model ID that was used to create the tokens from the input |
| 49 | +text. |
| 50 | + |
| 51 | +`model_text`:::: |
| 52 | +(Required, string) |
| 53 | +The query text you want to use for search. |
| 54 | + |
| 55 | + |
| 56 | +[discrete] |
| 57 | +[[text-expansion-query-notes]] |
| 58 | +=== Notes |
| 59 | + |
| 60 | +The following is an example of the `text_expansion` query that references the |
| 61 | +ELSER model to perform semantic search. For a more detailed description of how |
| 62 | +to perform semantic search by using ELSER and the `text_expansion` query, refer |
| 63 | +to <<semantic-search-elser,this tutorial>>. |
| 64 | + |
| 65 | +[source,console] |
| 66 | +---- |
| 67 | +GET my-index/_search |
| 68 | +{ |
| 69 | + "query":{ |
| 70 | + "text_expansion":{ |
| 71 | + "ml.tokens":{ |
| 72 | + "model_id":".elser_model_1", |
| 73 | + "model_text":"How is the weather in Jamaica?" |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | +} |
| 78 | +---- |
| 79 | +// TEST[skip: TBD] |
0 commit comments