I have a field studyLabel with values like "GSM-ABC123" where "GSM-" is always the same and the second part 'ABC123' is the actual ID. I need a document with such an ID to be matched by ''GSM-ABC123" or "ABC123", but search for "GSM" should not return anything.
This is how I configured the field:
{
"settings": {
"index": {
"analysis" : {
"filter": {
"study_label_id_only_filter" : {
"type": "pattern_replace",
"pattern": "^GSM-(.*)",
"replacement": "$1"
}
},
"analyzer": {
"study_label_analyzer": {
"tokenizer": "whitespace",
"filter": [
"study_label_id_only_filter"
]
}
}
}
}
},
"mappings": {
"study": {
"properties": {
"studyLabel": {
"type": "string",
"index": "not_analyzed",
"fields": {
"idOnly": {
"type": "string",
"analyzer": "study_label_analyzer"
}
}
}
}
}
}
}
This way, studyLabel only matches the full id "GSM-ABC123" (and does NOT match "GSM" or "ABC123" ) and studyLabel.idOnly only matches "ABC123" (and does NOT match "GSM" or "GSM-ABC123").
But, when I query match: { "_all", "GSM"}
I still get ALL the documents back. Any ideas why?