ELSER text expansion
editELSER text expansion
editUsing Elastic’s ELSER machine learning model you can easily incorporate text expansion for your queries. This works by using ELSER to provide automatic semantic enrichments to your documents upon ingestion, combined with the power of using templates in Search Applications to provide automated text expansion.
Availability and prerequisites
editThe ELSER text expansion model for ingestion and query expansion is a technical preview feature. Technical preview features are subject to change and are not covered by the support SLA of generally available (GA) features. Elastic plans to promote this feature to GA in a future release.
ELSER text expansion was introduced in Elastic version 8.8.0.
The ELSER model requires at least one ML node with a minimum of 4GB of memory.
Deploying the ELSER model
editYou can download and deploy ELSER either from the Machine Learning Trained Models page, or it can be deployed and started while configuring an ingestion pipeline.
If ELSER is not yet deployed, when you create or edit an ingestion pipeline you will have the option to deploy it from within your pipeline configuration.
Clicking the "Deploy" button will initiate the ELSER model deployment. This may take several minutes and the panel will let you know when it is ready. The deployment happens in the background and you can continue configuring your model while it is being deployed.
Once your ELSER model is deployed, you can then click to start the model in a single threaded instance, or, go to the trained models configuration to fine-tune the model deployment and start it.
When your ELSER model is deployed and started, it is ready to be used in a pipeline.
Creating a pipeline using ELSER
editOnce your ELSER model has been started, you can use the "Add Inference Pipeline" button to add the power of ELSER to your ingestion.
When configuring a pipeline, choose to create a new pipeline or use an existing one, and select the ELSER Text Expansion model, named ".elser_model_1".
Be certain to copy and customize the default pipeline before adding the ELSER inference processor. If not, the "Add Inference Pipeline" button will be disabled.
ELSER inference works across text fields, and best on shorter spans of text. During the pipeline creation, you have the option to test your pipeline results and you can select an existing document, or, add in a test document or two to test the model inference. You can view the results of the inference in the created "ml" field within the resulting document.
Once your pipeline is created, you are ready to ingest documents and utilize ELSER for text expansions in your search queries.
Querying documents with ELSER enrichments
editThe easiest way to get up and running using ELSER text expansion in your queries is to use the Search Applications feature.
Examples on how to create and use Search Application templates can be found in the template examples.
You can also use the ELSER model via the Elasticsearch _search
API using the text_expansion query.
Using the Kibana Dev Tools console, or an API call on the _search
endpoint, add the key text_expansion
and set the model_id
to the ELSER model under your fieldname.
The model_text
field should be filled in with the text of your query you wish to perform text expansion on.
Limitations and notes
editThere are several caveats, limitations and notes to be aware of when using ELSER text expansion. These include:
- When using a self-managed Elastic deployment, to deploy ELSER automatically your cluster must have access to download the ELSER model from Elastic. Elastic Cloud deployments have access by default. If your self-managed Elastic deployment does not have external internet access, you can still deploy ELSER in an air-gapped environment.
-
ELSER works best on small-to-medium sized fields that contain natural language.
For connector or web crawler use cases, this aligns best with fields like title, description, summary, or abstract.
Be aware that ELSER encodes only the first 512 tokens of a field, so it may not be as good a match for
body_content
on web crawler documents, orbody
fields resulting from extracting text from office documents with connectors. - Larger documents will take longer at ingestion time, and inference time per document will also increase the more fields in a document that need to be processed.
- The more fields your pipeline has to perform inference on, the longer it will take per document to ingest.
- Document enrichment only happens at ingestion time. If you have an existing index that you wish to use ELSER text expansion on, you must re-ingest the data.
-
Your results may produce high recall within your corpus.
For example, a single term might be expanded to two dozen or more synonyms for each term, whereas using BM25 relevancy ranking alone, the same term might expand to only 3 or 4 n-grams or stems.
A document will be considered a valid result if any of the inferred terms match between a query and a document, even if they’re both very low confidence.
To limit the results, you may want to implement a
min_score
constraint in your query. -
Explainability of text expanded queries are sub-optimal.
You can use the
_explain
API for text expansion queries, and it will tell you which expanded terms were found in both the document and the query along with the scoring information. However, some of these terms won’t necessarily make sense at first glance. For example, you might get a term expansion with a value of##ing
(word ends in "ing") orch##
(word starts with "ch").
Furthermore, as ELSER is in technical preview, there are several current limitations of note:
- The model will only provide inference across the first 512 tokens, per selected field, in your document.
- Multi-valued fields are not directly supported and require a preceding join processor if you wish to use them. For example, a document with the following field definition:
{ "field": ["some", "values"] }
does not work with ELSER. If you have a multi-valued field such as this, you will want to put the field through a Join Processor within your pipeline first and then run ELSER inference on the joined field.