Elasticsearch Mapping
PUT testindex
{
"settings": {
"analysis": {
"filter": {},
"tokenizer": {
"my_tokenizer": {
"type": "ngram",
"min_gram": 3,
"max_gram": 3,
"token_chars": []
}
},
"analyzer": {
"my_analyzer": {
"tokenizer": "my_tokenizer",
"filter": ["lowercase"]
},
"hiphen_analyzer": {
"tokenizer": "whitespace",
"filter": ["lowercase"]
}
}
}
},
"mappings": {
"test": {
"properties": {
"catch_all": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"store": true,
"ignore_above": 256
},
"raw": {
"type": "text",
"store": true,
"analyzer": "hiphen_analyzer",
"search_analyzer": "whitespace"
},
"ngrams": {
"type": "text",
"store": true,
"analyzer": "my_analyzer"
}
}
},
"hostname": {
"type": "text",
"copy_to": "catch_all"
}
}
}
}
}
Documents
POST testindex/test
{
"hostname": "server-testing-01"
}
POST testindex/test
{
"hostname": "Dell Poweredge 111"
}
I have server hostnames such as "server-testing-01", "server-testing-02", "Dell Poweredge Server".
Created a mapping in elasticsearch with one field called hostname as "text" and copy_to field "catch_all".
For now only one field "hostname" but other fields will also be copied to catch_all field.
There is a global search box which helps customers search these hostnames and other data.
- When searched for "test" Results should have "server-testing-01", "server-testing-02". When searched for "power", results should have "Dell Poweredge Server". When searched for "edge", results should have "Dell Poweredge Server"
- When searched for exact "server-testing-01" result should contain only one result.
edit: Currently tried ngram custom analyzer which gives right results for some partial searches not all.
can some body how to achieve the partial search as well as exact search in elasticsearch ?