Hi!
Im experiencing a bit of weird results for my simple search use case.
We want to search for vendors, each vendor document has name
property.
Most of vendors names are few words at most (i.e not full sentences).
Having these documents:
[
{ name: "Facebook" },
{ name: "The North Face" },
{ name: "Facebook Donations" },
{ name: "Prop Face" },
{ name: "Simplifying Payments with Facebook Pay" }
{ name: "Facebook Advertising" },
{ name: "facebook pay" }
]
the expected results is something similar to this:
{ name: "Facebook" },
{ name: "facebook pay" },
{ name: "Facebook Donations" },
{ name: "Facebook Advertising" },
{ name: "Prop Face" },
{ name: "The North Face" },
{ name: "Simplifying Payments with Facebook Pay" }
As first try, iv’e tried setting a search index as String
field, Autocomplete
attempt will follow.
This is the index definition:
{
"mappings": {
"dynamic": false,
"fields": {
"name": {
"type": "string"
}
}
},
"storedSource": true
}
this is the query:
{
$search: {
index: 'default',
text: {
path: 'name',
query: 'face'
}
}
}
returns
[
{ name: "Prop Face" },
{ name: "The North Face" }
]
which completely doesn’t make sense, probably i’m doing something wrong?
when moving to autocomplete
index with this definition:
{
"mappings": {
"dynamic": false,
"fields": {
"name": [
{
"dynamic": true,
"type": "document"
},
{
"type": "autocomplete"
}
]
}
},
"storedSource": true
}
having this query:
{
$search: {
index: 'default',
autocomplete: {
path: 'name',
query: 'face',
}
}
}
i’m getting these results:
[
{ name: "Facebook Donations" },
{ name: "Facebook Advertising" },
{ name: "facebook pay" },
{ name: "Simplifying Payments with Facebook Pay" },
{ name: "Facebook" },
{ name: "Prop Face" },
{ name: "The North Face" },
]
Which much closer to the desired result but still “Facebook” comes after “Simplifying Payments with Facebook Pay” for some reason, i would expect it to be found first.
any ideas or suggestions?