Partial search on particular field

I have an appsearch engines with the following documents

[{
"id": 1,
"category": ["television"],
"name": "ABC Television"
}, {
"id": 2,
"category": ["fridge"],
"name": "Tele Fridge"
}]

How can I do partial search on particular fields. Like in this example, say I want to search for all documents where category matches "fridg" and name matches "tele" such that it returns document with id:2, how can I do that?

There's no way to specify in a query something like:

  • Search ONLY the "category" field for the term "fridg"
  • Search ONLY the "name" field for the term "text"

For partial matching, you would place both terms in the "query" parameter. App Search will search all fields by default, so you would get a hit on document 2.

{
  "query": "tele fridg"
}

You'll also get a hit on document 1 in this case, but document 2 should rank higher because it is a better match. And if that's not the case you can tweak your relevance tuning.

Thanks for the reply.

We are looking to build a advanced search widget where people can type in text values corresponding to each field(eg: a text field for category and another one for name). So it won't be right to do a generic query across both fields together. Is there any other way you can suggest to solve this problem?

Are native elasticsearch search APIs exposed if we are using appsearch?

No, the native APIs are not exposed.

I'm not sure that you'll find a way to make App Search work exactly as you are hoping to.

The closest approximation you could get would be to make the search_fields configurable. Meaning, instead of letting users apply text searches per field, have users apply a single text search but be able to limit the fields that are searched.

Ultimately, your goal with the Advanced Search is to give users more control over their query in order to help them find exactly what they're looking for. App Search has facilities to do that, though it may not match 1 to 1 with how you were expecting to accomplish it.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.