Analyze a field twice and store results together with elasticsearch

128 views Asked by At

Is it possible to analyze a field that has already been analyzed?

For example, suppose we broke down /Health & Beauty/Vitamins & Supplements/Supplements into the following using a custom analysis with a hierarchical token:
/Health & Beauty
/Health & Beauty/Vitamins & Supplements
/Health & Beauty/Vitamins & Supplements/Supplements

Would it be possible to then run a separate analysis on each new string and store the results with the corresponding string?

How would we do that with the following mapping:

PUT /my_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "path-analyzer": {
          "type": "custom",
          "tokenizer": "path-tokenizer"
        },
        "url-analyzer": {
          "type": "custom",
          "char_filter" : ["urlFormat"],
          "filter": ["lowercase"],
          "tokenizer": "path-tokenizer"
        },
        "cat-analyzer": {
          "type": "custom",
          "char_filter" : ["catName"],
          "tokenizer": "keyword"
        }
      },
      "char_filter" : {
        "urlFormat":{
          "type":"pattern_replace",
          "pattern":"[^a-z|A-Z|/]+",
          "replacement":"-"
        },
        "catName":{
          "type":"pattern_replace",
          "pattern":"[^/]+/",
          "replacement":""
        }
      },
      "tokenizer": {
        "path-tokenizer": {
          "type": "path_hierarchy"
        }
      }
    }
  },
  "mappings": {
    "my_type": {
      "dynamic": "strict",
      "properties": {
        "group_path": {
          "type": "string",
          "index_analyzer": "url-analyzer",
          "search_analyzer": "keyword",
          "fields": {
            "name": {
              "type": "string",
              "index_analyzer": "cat-analyzer",
              "search_analyzer": "keyword"
            }
          }
        }
      }
    }
  }
}

Thank you for your consideration

0

There are 0 answers