问题
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 :
- it will retrieve only children of
structural
. - It will return all the leaf nodes i.e.
components
,directives
andlogistics
.
I tried running below query but it retrieves all the records.
POST elastic_course/book/_search
{
"query": {
"regexp": {
"path.":"/structural"
}
}
}
any help?
Thanks.
来源:https://stackoverflow.com/questions/43249637/how-to-query-fields-with-path-hierarchy-analyzer-in-elasticsearch