Reputation: 11
This is my current setup the I have for my user_info index
PUT user_info
{
"mappings": {
"properties": {
"username": {
"type": "text",
"fields": {
"autocomplete": {
"type": "text",
"analyzer": "autocomplete"
},
"raw": {
"type": "keyword",
"normalizer": "my_normalizer"
}
}
},
"telephone": {
"type": "text",
"fields": {
"autocomplete": {
"type": "text",
"analyzer": "autocomplete"
},
"raw": {
"type": "keyword",
"normalizer": "my_normalizer"
}
}
}
}
},
"settings": {
"analysis": {
"filter": {
"edge_ngram_filter": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 10
}
},
"normalizer": {
"my_normalizer": {
"type": "custom",
"char_filter": [],
"filter": ["lowercase", "asciifolding"]
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"edge_ngram_filter"
]
}
}
}
}
}
Now when I run this search query
GET user_info/_search
{
"from": 0,
"size": 20,
"query": {
"bool": {
"should": [
{
"match": {
"username.autocomplete": {
"query": "Eli Hub"
}
}
},
{
"prefix": {
"username.raw": {
"value": "Eli Hub"
}
}
}
]
}
}
}
These are the results
"hits": [
{
"_index": "user_info",
"_id": "1",
"_score": 1.9736931,
"_source": {
"username": "Eli Huber"
}
},
{
"_index": "user_auth_cards_info",
"_id": "6",
"_score": 0.518771,
"_source": {
"username": "Elly Eli"
}
},
{
"_index": "user_info",
"_id": "4",
"_score": 0.50130737,
"_source": {
"username": "Sherlyn Eli"
}
},
{
"_index": "user_info",
"_id": "2",
"_score": 0.47586513,
"_source": {
"e_name": "Eli Rios"
}
},
{
"_index": "user_auth_cards_info",
"_id": "7",
"_score": 0.3256223,
"_source": {
"username": "Eli "
}
},
{
"_index": "user_info",
"_id": "3",
"_score": 0.31583264,
"_source": {
"username": "Eli Bender"
}
},
{
"_index": "user_info",
"_id": "5",
"_score": 0.31583264,
"_source": {
"username": "Breanna Eli"
}
}
]
I don't understand how I would go about sorting these results and getting them to all start with Eli first or if it's even possible with the index setup I have. Initially I had a prefix query setup with a boost of 2 and then a wildcard query. Which worked however it would be a performance issue at a later stage so trying to figure it out this way.
Upvotes: 0
Views: 22