Best way to store multi value to specific field

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

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:


        "_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 ?

Hi @elasticpatrick,

What is your request to search for the tags field?

I try to query like this

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

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.

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.

Something like an inverted index.

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

"_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

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 ?

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