Hi,
I am creating a search engine with the help of mongo Atlas search,
This is the mapping I am using for $search in aggregation query,
{
"analyzer":"lucene.standard",
"searchAnalyzer":"lucene.standard",
"mappings":{
"dynamic":true,
"fields":{
"bestProduct":{
"fields":{
"productName":[
{
"analyzer":"lucene.simple",
"searchAnalyzer":"lucene.simple",
"type":"string"
},
{
"analyzer":"lucene.standard",
"maxGrams":3,
"minGrams":15,
"tokenization":"edgeGram",
"type":"autocomplete"
}
]
},
"type":"document"
},
"brandName":[
{
"analyzer":"lucene.simple",
"searchAnalyzer":"lucene.simple",
"type":"string"
},
{
"type":"autocomplete"
}
]
}
}
}
and this is the aggregation query
{
"$search":{
"compound":{
"should":[
{
"term":{
"query":"organic",
"path":[
"bestProduct.productName"
],
"score":{
"boost":{
"value":10
}
}
}
},
{
"autocomplete":{
"query":"organic",
"path":"bestProduct.productName",
"score":{
"boost":{
"value":50
}
}
}
}
]
}
}
}
I am getting this as output
{
"bestProduct":{
"productName":"Samisha organic"
}
},
{
"bestProduct":{
"productName":"childern organic"
}
},
{
"bestProduct":{
"productName":"organic"
}
}
I want to know, how can I get the matching word first, and also if the search_key = “organ” still I want products with a name starting with “organ*” shows first, Can anyone help?