# Best way to store multi value to specific field

**URL:** <https://discuss.elastic.co/t/best-way-to-store-multi-value-to-specific-field/194692>\
**Category:** Elasticsearch\
**Created:** [August 10, 2019, 5:37am UTC](https://discuss.elastic.co/t/best-way-to-store-multi-value-to-specific-field/194692 "2019-08-10T05:37:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![elasticpatrick](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticpatrick/32/49939_2.png) [@elasticpatrick](https://discuss.elastic.co/u/elasticpatrick)\
**Post date:** [August 10, 2019, 5:37am UTC](https://discuss.elastic.co/t/best-way-to-store-multi-value-to-specific-field/194692/1 "2019-08-10T05:37:16Z")

</div>

Hello, I have e-commerce store where I have generated automated tags for the my products. Each product can have approximately 100-120 tags on it. Now I would like to do match query and retrieve only specific tags from that products. I don't know how to store the tags for specific product. Hence I have stored it in an array. Here is the mapping

```auto
mappings": {
      "properties": {
        "product_name": {
          "type": "text",
          "store": true,
          "analyzer": "autocomplete",
          "search_analyzer": "autocomplete_search"
        },
        "tags": {
          "type": "text",
          "store": true,
          "analyzer": "autocomplete",
          "search_analyzer": "autocomplete_search"
        }
      }
    }

```

They way I documents index are like this:

```auto

        "_index": "product_details",
        "_type": "_doc",
        "_id": "2",
        "_score": 1.0,
        "_source": {
          "tags": [
            "black_color",
            "wireless",
            "amazon_deals"
          ],
          "product_name": "alexa"
        }
      },
      {
        "_index": "product_details",
        "_type": "_doc",
        "_id": "1",
        "_score": 1.0,
        "_source": {
          "tags": [
            "bluetooth",
            "wireless",
            "best_deals"
          ],
          "product_name": "handfree"
        }

```

Now I can't not retrieve specific tags from the keywords type by the user. Is there any why to do it or any other way to store this type of data ?

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [August 10, 2019, 6:08am UTC](https://discuss.elastic.co/t/best-way-to-store-multi-value-to-specific-field/194692/2 "2019-08-10T06:08:04Z")

</div>

Hi @elasticpatrick,

> [@elasticpatrick](#):
>
> Now I can't not retrieve specific tags from the keywords type by the user.

What is your request to search for the tags field?

---

<div class="post-metadata">

**Author:** ![elasticpatrick](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticpatrick/32/49939_2.png) [@elasticpatrick](https://discuss.elastic.co/u/elasticpatrick)\
**Post date:** [August 10, 2019, 6:11am UTC](https://discuss.elastic.co/t/best-way-to-store-multi-value-to-specific-field/194692/3 "2019-08-10T06:11:57Z")

</div>

I try to query like this

```auto
GET product_details/_search
{
  "query": {
    "match": {
      "tags": "bl"
    }
  }
  }

```

And I would like to get only matched tags like "bluetooth" and "black". But instead I got the both documents in hits

---

<div class="post-metadata">

**Author:** ![elasticpatrick](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticpatrick/32/49939_2.png) [@elasticpatrick](https://discuss.elastic.co/u/elasticpatrick)\
**Post date:** [August 10, 2019, 6:13am UTC](https://discuss.elastic.co/t/best-way-to-store-multi-value-to-specific-field/194692/4 "2019-08-10T06:13:12Z")

</div>

Maybe I want to try to arrange data in different . But don't know how to arrange those data so that I can get the satisfactory results.

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [August 11, 2019, 2:19pm UTC](https://discuss.elastic.co/t/best-way-to-store-multi-value-to-specific-field/194692/5 "2019-08-11T14:19:16Z")

</div>

Hi,

If I understand correctly your need, you want to return tags but not documents?  
If you search "bl" you want the search to return bluetooth not the full document with a list of tags?

If my guess is correct, you need to index your tags in a different index with each tags as document with the products link.

> [@elasticpatrick](#):
>
> "\_source": { "product\_id": [1, ...], "tag": "bluetooth" }

Something like an inverted index.

---

<div class="post-metadata">

**Author:** ![elasticpatrick](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticpatrick/32/49939_2.png) [@elasticpatrick](https://discuss.elastic.co/u/elasticpatrick)\
**Post date:** [August 12, 2019, 1:15pm UTC](https://discuss.elastic.co/t/best-way-to-store-multi-value-to-specific-field/194692/6 "2019-08-12T13:15:37Z")

</div>

Yes, you understood correctly. Thanks for the answer. But the problem in this is that if I have provided some tag in advance, then I would like to get those tags that are present on some product having provided tag and do the match query on all those other tags. So that to get related tags from the products.  
Say for example I have given the tags name on product

```auto
"_source": {
   "product_name" : "mobile",
   "tags" = ["wireless", "bluetooth"]
}
"_source": {
   "product_name" : "hairdryer",
   "tags" = ["wrong_choice", "warm"]
}
"_source": {
   "product_name" : "handfree",
   "tags" = ["western_product", "bluetooth"]
}

```

Then if I do match query with

```auto
GET product_details/_search
{
  "query": {
    "match": {
      "tags": "wi"
       }
     }
   }

```

and I have provided "bluetooth" tag , then how can I able to get tag name "wireless" and "western\_product" from the documents and not the "wrong\_choice" choice tag from the documents ?

---

<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 9, 2019, 1:15pm UTC](https://discuss.elastic.co/t/best-way-to-store-multi-value-to-specific-field/194692/7 "2019-09-09T13:15:38Z")

</div>

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