How To USE "IN" In FTS

Hi,
I need to use multiple search in one field on FTS.
For example;
[{
“categories”:[11,12,13]
},
{
“categories”:[11,12,16]
}]

how to search in categories contains 11 and 12 values.
Thanks.

Remember FTS returns “document IDs” as hits for a search request.

  • If each document has a field such as {"categories": [11,12,13]} - then you can simply index categories as a numeric field and run a conjunction query over it …
{
  "query": {
    "conjuncts": [
      {
        "field": "categories",
        "min": 11,
        "max": 11,
        "inclusive_min": true,
        "inclusive_max": true
      },
      {
        "field": "categories",
        "min": 12,
        "max": 12,
        "inclusive_min": true,
        "inclusive_max": true
      }
    ]
  }
}
  • If you however have multiple array elements in your document such as …
[
  {
    "categories":[11,12,13]
  },
  {
    "categories":[14,15,16]
  }
]

… and you wish to return the document as a hit ONLY if a single array subobject has both 11 and 12 - then this is NOT possible with couchbase FTS at the moment.

This is because FTS flattens arrays and in doing so, it does not save the element position within arrays which is needed to determine which subobject in an array an element belongs to.

I’d recommend looking into N1QL queries with secondary indexes to achieve this. cc @vsr1 .

Hi @abhinav,
Your solution solve my problem.
Thank you.
I use it like this;

                int id = Convert.ToInt32(catId);
                mustQueries.And(new NumericRangeQuery()
                                        .Field("categories.categoryId")
                                        .Min(id, true)
                                        .Max(id, true))
                                        .Boost(6);

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