I'm using the Completion Suggester in Elasticsearch to allow partial word matching queries. In my index (products_index), I'd like to be able to query both the product_name field and the brand field. Here are my mappings:
POST /product_index
mappings: {
products: {
properties: {
brand: {
type: "string",
analyzer: "english"
},
product_name: {
type: "string",
analyzer: "english"
},
id: {
type: "long"
},
lookup_count: {
type: "long"
},
suggest: {
type: "completion",
analyzer: "simple",
payloads: true,
preserve_separators: true,
preserve_position_increments: true,
max_input_length: 50
},
upc: {
type: "string"
}
}
}
}
Here is my data:
POST /product_index/products/2
{
id: 2,
brand: "Coca-Cola",
product_name: "Classic Coke",
suggest: {
input: [
"Classic Coke",
"Coca-Cola"
],
output: "Classic Coke - Coca-Cola",
payload: {
id: 2,
product_name: "Classic Coke",
brand: "Coca-Cola",
popularity: 10
},
weight: 0
}
}
And here is my query:
POST /product_index/_search
"suggest": {
"product_suggest": {
"text": 'coca-co',
"completion": {
"field": 'suggest'
}
}
}
This works great except that I'd like to give the product_name field a higher weighting than the brand field. Is there any way I can achieve this? I have looked into this article on using bool queries but I'm quite new to Elasticsearch and unsure how I can apply that in the case of completion suggester.
Thanks a lot!