# Using ELSER for multiple fields

**URL:** <https://discuss.elastic.co/t/using-elser-for-multiple-fields/341347>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-machine-learning\
**Created:** [August 22, 2023, 9:13am UTC](https://discuss.elastic.co/t/using-elser-for-multiple-fields/341347 "2023-08-22T09:13:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rottonscope](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@Rottonscope](https://discuss.elastic.co/u/Rottonscope)\
**Post date:** [August 22, 2023, 9:13am UTC](https://discuss.elastic.co/t/using-elser-for-multiple-fields/341347/1 "2023-08-22T09:13:38Z")

</div>

Hello! I've just begun exploring ELSER and I'm interesting in knowing if there is any guidance out there for scenarios whereby I want to run inference on multiple fields, e.g. Title and also Description.

The documentation online ([Tutorial: semantic search with ELSER | Elasticsearch Guide [8.9] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/8.9/semantic-search-elser.html)) shows just one text field being used.

My scenario includes both Title and Description fields, whereby I want to apply a boost to the Title field, as such I need both Title and Description to remain separated but also processed via the ELSER model.

Is it possible to have a Document with multiple fields, each of which make use of the ELSER model?

Is there any documentation online or perhaps someone can advise?

---

<div class="post-metadata">

**Author:** ![wei.wang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wei.wang/32/51803_2.png) [@wei.wang](https://discuss.elastic.co/u/wei.wang)\
**Post date:** [August 24, 2023, 7:44pm UTC](https://discuss.elastic.co/t/using-elser-for-multiple-fields/341347/2 "2023-08-24T19:44:16Z")

</div>

Hi,

Thanks for trying ELSER. Regarding your question how to run inference on multiple fields, we don't have an official guidance at this moment. However, you can follow the below steps:

1. Create the index mapping for the destination index

```auto
PUT my-index
{
  "mappings": {
    "properties": {
      "ml_title.tokens": { 
        "type": "rank_features" 
      },
      "ml_description.tokens": { 
        "type": "rank_features" 
      },          
      "title": { 
        "type": "text" 
      },
      "description": { 
        "type": "text" 
      }  
    }
  }
}

```

1. Create an ingest pipeline with two inference processors:

```auto
PUT _ingest/pipeline/elser-v1-test
{
  "on_failure": [
    {
      "set": {
        "description": "Record error information",
        "field": "error_information",
        "value": "Processor {{ _ingest.on_failure_processor_type }} with tag {{ _ingest.on_failure_processor_tag }} in pipeline {{ _ingest.on_failure_pipeline }} failed with message {{ _ingest.on_failure_message }}"
      }
    }
  ],
  "processors": [
    {
      "inference": {
        "model_id": ".elser_model_1",
        "target_field": "ml_title",
        "field_map": {
          "title": "text_field"
        },
        "inference_config": {
          "text_expansion": {
            "results_field": "tokens"
          }
        }
      }
    },
    {
      "inference": {
        "model_id": ".elser_model_1",
        "target_field": "ml_description",
        "field_map": {
          "description": "text_field"
        },
        "inference_config": {
          "text_expansion": {
            "results_field": "tokens"
          }
        }
      }
    }
  ]
}

```

1. Run reindex and ingest the data through the inference ingest pipeline

```auto
POST _reindex?wait_for_completion=false
{
  "source": {
    "index": "test-data",
    "size": 50 
  },
  "dest": {
    "index": "my-index",
    "pipeline": "elser-v1-test"
  }
}

```

1. After reindex is complete, you can use bool query to perform semantic search on both fields:

```auto
GET my-index/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "text_expansion": {
            "ml_title.tokens": {
              "model_id": ".elser_model_1",
              "model_text": "Some text"
            }
          }
        },
        {
          "text_expansion": {
            "ml_description.tokens": {
              "model_id": ".elser_model_1",
              "model_text": "Some text"
            }
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 21, 2023, 7:45pm UTC](https://discuss.elastic.co/t/using-elser-for-multiple-fields/341347/3 "2023-09-21T19:45:02Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
