Problem while searching number fields partially with Prefix query

I have created a collection like below

rows


"rowb": {
  "rowId": "rowb",
  "firstName": "Kaushal",
  "lastName": "Patel",
  "mobileNumber": "+911234567890",
  "age": 33
}

"rowa":{
  "rowId": "rowa",
  "firstName": "Vikram",
  "lastName": "Kumar",
  "age": 260
}

"rowc":{
  "rowId": "rowc",
  "firstName": "Maulik",
  "lastName": "Patel",
  "age": 24
}

Created FTS index on above collection and also checked “include in _all” field for all the fields “Note” :I have checked the “include in _all” for age field which is number field as well.

now I am trying to search with below

{"conjuncts":[{"prefix":"vik"},{"prefix":"ku"},{"prefix":"26"}]}

I am expecting result to be as it has number 260 as match for above however it does not give me any result.

"rowa":{
  "rowId": "rowa",
  "firstName": "Vikram",
  "lastName": "Kumar",
  "age": 260
}

However if I run the query with below

{"conjuncts":[{"prefix":"vik"},{"prefix":"ku"},{"query":"260"}]}

Can someone share expertise why “query” type query works and “prefix” query not working ? What is other way I want to partially patch “age” field to return records ?

Hello @kirtan.patel!

So I see 2 types of data in your JSON documents - string and number. It will be up to you to identify your data type before defining the index definition. You’ve done this bit correctly.

However, not all queries are applicable over all data types. Here’s a list of queries we support and what data types they’re applicable over.

  • Match … applicable on strings
  • Match phrase … applicable on strings
  • Term … applicable on strings
  • Phrase … applicable on strings
  • Prefix … applicable on strings
  • Regexp … applicable on strings
  • Fuzzy … applicable on strings
  • Wildcard … applicable on strings
  • Numeric range … applicable on numbers
  • Date range … applicable on strings conforming to a datetime format ISO-8601
  • Term range … applicable on strings
  • Geo spatial queries … applicable on geo spatial content (look into docs for more information)

There’s documentation on all of these here - Supported Queries | Couchbase Docs

So you trying to perform a prefix query - {"prefix": "26"} will not match any hits, because there aren’t any string tokens indexed matching that. There’s numeric data though. The only way you can access them is via a numeric range query, here’s how that would look …

{"min": 26, "inclusive_min": true, "field": "age"}

The field setting above is optional for your index definition, because like you already pointed out - you’ve selected include in _all field.

Now, here’s how your conjunction query will need to look for your index definition …

{
  "conjuncts": [
    {
      "prefix": "vik"
    },
    {
      "prefix": "ku"
    },
    {
      "min": 26,
      "inclusive_min": true
    }
  ]
}

On your question on the query string syntax works - if you use {"query": "260"}, this is the query string query syntax - that automatically determines the type of the string value provided to apply the appropriate query. Here the search engine will determine 260 is a number and a numeric range query of the above syntax will automatically ensue underneath the hood.