2

I have configured path_analyzer in elasticsearch using below configuration.

PUT /elastic_course
{
  "settings": {
    "analysis": {
      "analyzer": {
        "path_analyzer": {
          "tokenizer": "path_tokenizer"
        },
        "reverse_path_analyzer": {
          "tokenizer": "path_tokenizer"
        }
      },
      "tokenizer": {
        "path_tokenizer": {
          "type": "path_hierarchy",
          "delimiter": "/",
          "replacement": "-"
        },
        "reverse_path_tokenizer": {
          "type": "path_hierarchy",
          "delimiter": "/",
          "replacement": "-"
        }
      }
    }
  },
  "mappings": {
    "book" : {
        "properties": {
           "author": {
              "type": "string",
              "index": "not_analyzed"
           },
           "genre": {
              "type": "string",
              "index": "not_analyzed"
           },
           "score": {
              "type": "double"
           },
           "synopsis": {
              "type": "string",
              "index":"analyzed",
              "analyzer":"english"
           },
           "title": {
              "type": "string"
           },
           "path":{
              "type":"string",
              "analyzer":"path_analyzer",
              "fields": {
                "reverse": {
                  "type":"string",
                  "analyzer":"reverse_path_analyzer"
                }
              }
          }
      }
    }
  }
}

Now I have inserted four documents where path values are :

  • /angular/structural
  • /angular/structural/directives
  • /angular/structural/components
  • /angular/logistics

Now I want to query my index such as :

  1. it will retrieve only children of structural.
  2. It will return all the leaf nodes i.e. components , directives and logistics.

I tried running below query but it retrieves all the records.

POST elastic_course/book/_search
{
  "query": {
    "regexp": {
      "path.":"/structural"
    }
  }
}

any help?

Thanks.

Bhushan Gadekar
  • 13,485
  • 21
  • 82
  • 131
  • When you say "retrieve only children", it is not clear whether you want the full documents to be returned or only the tokens `directives` and `components`. Same thing for question 2. – Val Apr 17 '17 at 07:17
  • @Val retrieving only tokens would be enough. in above scenario, i would like to get tokens `directives` , `components` and `logistics`. as they are leaf nodes. is it possible? – Bhushan Gadekar Apr 17 '17 at 09:29
  • By default, ES will return the matching documents, but not single tokens that have been indexed in the context of one document. – Val Apr 17 '17 at 09:48
  • @BhushanGadekar did you ever resolve this? I have a same problem – Vikas Oct 23 '21 at 20:23

0 Answers0