Reputation: 3423
My objective is to create an index + search pipeline, so I can find the following document by searching for "reprod":
{ name: "can you find this and reproduce?" }
What I have:
I'm using the default index. My search pipeline looks like this:
$search: {
text: {
query: 'reprod',
path: 'name',
},
},
But this does not work - I only get the full result when I provide the entire word in the query. I would like the document to be returned, even if I only provide a subset of a word.
Upvotes: 2
Views: 1156
Reputation: 166
If you can change your index definition, I'd suggest using the autocomplete operator but fields on which you query using this operator currently require them to be statically defined in the index definition. For this example, your index definition could look something like this:
{
"mappings": {
"dynamic": false,
"fields": {
"name": {
"type": "autocomplete"
}
}
}
}
And then your query would look like this:
{
$search: {
"autocomplete": {
"path": "name",
"query": "reprod"
}
}
}
If you don't want a statically defined index definition, you could use the Wildcard Operator instead with the Allow Analyzed Field
set to true
.
Upvotes: 5