# 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:** 1\
**Showing post:** 2

<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"
            }
          }
        }
      ]
    }
  }
}

```

---

_[View the full topic](https://discuss.elastic.co/t/using-elser-for-multiple-fields/341347)._
