# Copy\_to vs appending all terms in a string : Are the search results going to be the same?

**URL:** <https://discuss.elastic.co/t/copy-to-vs-appending-all-terms-in-a-string-are-the-search-results-going-to-be-the-same/308385>\
**Category:** Elasticsearch\
**Created:** [June 28, 2022, 5:37pm UTC](https://discuss.elastic.co/t/copy-to-vs-appending-all-terms-in-a-string-are-the-search-results-going-to-be-the-same/308385 "2022-06-28T17:37:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ano](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@ano](https://discuss.elastic.co/u/ano)\
**Post date:** [June 28, 2022, 5:37pm UTC](https://discuss.elastic.co/t/copy-to-vs-appending-all-terms-in-a-string-are-the-search-results-going-to-be-the-same/308385/1 "2022-06-28T17:37:03Z")

</div>

Hi,

I'm building an e-commerce search engine, and I want to do a full text search on product name, category, and a few other fields. I'm currently using copy\_to to copy all the individual fields into 1 single field (called 'fullTextSearchTerms'), analyzing that field(with phonetic filter, stemmers etc), and doing a match query on it.

I'm exploring an alternative to copy\_to, where during index time, I will create the 'fullTextSearchTerms' field by appending the individual fields in a space separated way, like so :

`fullTextSearchTerms = productName + " " + productCategory + " " + ...`

And I index this field explicitly.

As per my understanding, the search experience should remain the same for these 2 methods of indexing, but am I missing anything? Are these two methods effectively not interchangeable in terms of search experience?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [June 29, 2022, 3:14pm UTC](https://discuss.elastic.co/t/copy-to-vs-appending-all-terms-in-a-string-are-the-search-results-going-to-be-the-same/308385/2 "2022-06-29T15:14:33Z")

</div>

`copy_to` stores copied values in array.

Whether the search experience is interexchangeable depends on the analyzer. In addition the result could be different for match\_phrase query if the phrase hit over productName and productCategory.

If you creat `fullTextSearchTerms` as array, the result could be interchangeable completely.

Sample:

```auto
PUT test-index-000001
{
  "mappings": {
    "properties": {
      "first_name": {
        "type": "text",
        "copy_to": "full_name" 
      },
      "last_name": {
        "type": "text",
        "copy_to": "full_name" 
      },
      "full_name": {
        "type": "text"
      }
    }
  }
}

PUT test-index-000001/_doc/1
{
  "first_name": "John",
  "last_name": "Smith"
}

GET test-index-000001/_search
{
  "query": {
    "match": {
      "full_name": { 
        "query": "John Smith",
        "operator": "and"
      }
    }
  },
  "fields":["*"]
}

# see the "full_name" field
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 0.5753642,
    "hits" : [
      {
        "_index" : "test-index-000001",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 0.5753642,
        "_source" : {
          "first_name" : "John",
          "last_name" : "Smith"
        },
        "fields" : {
          "last_name" : [
            "Smith"
          ],
          "first_name" : [
            "John"
          ],
          "full_name" : [
            "Smith",
            "John"
          ]
        }
      }
    ]
  }
}

```

---

<div class="post-metadata">

**Author:** ![ano](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@ano](https://discuss.elastic.co/u/ano)\
**Post date:** [July 12, 2022, 3:09am UTC](https://discuss.elastic.co/t/copy-to-vs-appending-all-terms-in-a-string-are-the-search-results-going-to-be-the-same/308385/3 "2022-07-12T03:09:14Z")

</div>

> [@Tomo\_M](#):
>
> `copy_to` stores copied values in array.
> 
> Whether the search experience is interexchangeable depends on the analyzer. In addition the result could be different for match\_phrase query if the phrase hit over productName and productCategory.
> 
> If you creat `fullTextSearchTerms` as array, the result could be interchangeable completely.
> 
> Sample

Thanks for your response!

---

<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:** [August 9, 2022, 3:09am UTC](https://discuss.elastic.co/t/copy-to-vs-appending-all-terms-in-a-string-are-the-search-results-going-to-be-the-same/308385/4 "2022-08-09T03:09:53Z")

</div>

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