N1QL + FTS with 2 type mappings

Hi,

Below is my index:

{
  "type": "fulltext-index",
  "name": "books_one_two",
  "uuid": "3aa06c54b5da3a63",
  "sourceType": "couchbase",
  "sourceName": "books",
  "sourceUUID": "9d63fbea507bdb8a1e39b7b72dc0cba3",
  "planParams": {
    "maxPartitionsPerPIndex": 64,
    "indexPartitions": 1
  },
  "params": {
    "doc_config": {
      "docid_prefix_delim": "",
      "docid_regexp": "",
      "mode": "type_field",
      "type_field": "_class"
    },
    "mapping": {
      "analysis": {},
      "default_analyzer": "standard",
      "default_datetime_parser": "dateTimeOptional",
      "default_field": "_all",
      "default_mapping": {
        "dynamic": true,
        "enabled": false
      },
      "default_type": "_default",
      "docvalues_dynamic": true,
      "index_dynamic": true,
      "store_dynamic": false,
      "type_field": "_type",
      "types": {
        "com.org.One": {
          "dynamic": false,
          "enabled": true,
          "properties": {
            "field1": {
              "dynamic": false,
              "enabled": true,
              "fields": [
                {
                  "analyzer": "keyword",
                  "index": true,
                  "name": "field1",
                  "store": true,
                  "type": "text"
                }
              ]
            }
          }
        },
        "com.org.Two": {
          "dynamic": false,
          "enabled": true,
          "properties": {
            "field1": {
              "dynamic": false,
              "enabled": true,
              "fields": [
                {
                  "analyzer": "keyword",
                  "index": true,
                  "name": "field1",
                  "store": true,
                  "type": "text"
                }
              ]
            }
          }
        }
      }
    },
    "store": {
      "indexType": "scorch"
    }
  },
  "sourceParams": {}
}

**N1QL query:**
SELECT meta().id
FROM `books` as p
WHERE _class ='com.org.One'
and
SEARCH(p,{
"query": {
        "conjuncts": [
            {
                "field": "field1",
                "match": "abc def",
                "analyzer": "keyword",
                "operator": "or"
            }
        ]
    },
    "size": 2,
    "from": 0
    });

field1 is an array

  1. No index available error is coming.
  2. In curl query, i just want to get data for _class = ‘com.org.One’. How to add this constraint to JSON query? I tried below but did not work:
    “query”: {
    “conjuncts”: [
    {
    “field”: “field1”,
    “match”: “abc”
    },
    {
    “_type”: “_class”,
    “match”: “com.org.One”
    }
    ]
    }

Thanks
Nitesh

hi @Nitesh_Gupta,

A snippet from the doc links shared earlier - :slightly_frowning_face: :
" For more information on defining custom type mappings within the full-text search index, refer to Specifying Type Mappings. Note that for N1QL queries, only full-text search indexes with one type mapping are searchable.

This is doable since 6.6.0. I guess you were on an older release like 6.0.

If you don’t have any specific N1QL requirements or a stack already using N1QL or has a pure FTS use case, then it is always better to directly hit FTS for both performance reasons and for skipping the learning curve.

  • Not sure whether you understood what you are doing with this query.
{
“field”: “field1”,
“match”: “abc def”,
“analyzer”: “keyword”,
“operator”: “or”
}

As the query text analyzer is keyword, a single token is going to get generated out of it. ie “abc def” and then there is not much sense of giving an or operator there.

=> type identifier for mapping is just used for filtering the documents into the index. If you need to search on that type identifying field, then you need to index the _class field within each of those mappings. Then it would become searchable as you are trying here.

Cheers!

Thanks @sreeks

  1. Note that for N1QL queries, only full-text search indexes with one type mapping are searchable → this makes sense to me.
  2. i should have used analyzer as standard. Then it worked fine. Then it worked as pure OR operator.
  3. i need to index _class as well.

Thanks for clarifying and i am doing POC on 6.6.0 only. Can you please answer to this query FTS with N1QL - settings mismatch - #7 by Nitesh_Gupta ?