Problem with FTS Boolean query [err: cannot unmarshal array into Go value of type map]

Hi,
I am trying to build a boolean query for full text search with PHP SDK but keep getting this error:

[cb,EROR] (pcbc/cbft L:35) Failed to search in index. 400: {“error”:“rest_index: Query, indexName: fts_index_custom, err: bleve: QueryBleve parsing searchRequest, err: json: cannot unmarshal array into Go value of type map[string]in
terface {}”,“request”:{“ctl”:{“timeout”:75000},“indexName”:“fts_index_custom”,“query”:{“must”:[{“conjuncts”:[{“field”:“name”,“match”:“ltd”},{“field”:“department”,“match”:“ltd”}]}]}},“status”:“fail”} . I=0x55e1f76bc8f0

By analyzing the error message it is obvious bleve parser is getting array as a “must” part of the query but it is expecting an object. There is an example of the boolean query in the docs and the “must” part of the query is clearly an object.

Query produced by PHP SDK

"ctl": {
    "timeout": 75000
},
"indexName": "fts_index_custom",
"query": {
    "must": [
        {
            "conjuncts": [
                {
                    "field": "name",
                    "match": "ltd"
                },
                {
                    "field": "department",
                    "match": "main"
                }
            ]
        }
    ]
}

Query expected by Bleve parser (tested and works with FTS REST API)

"ctl": {
    "timeout": 75000
},
"indexName": "fts_index_custom",
"query": {
     "must": {
            "conjuncts": [
                {
                    "field": "name",
                    "match": "ltd"
                },
                {
                    "field": "department",
                    "match": "main"
                }
            ]
        }
}

This is the code I use to generate the query.

    //Field queries
    $firstQuery = SearchQuery::match("ltd")->field("name");
    $secondQuery = SearchQuery::match("main")->field("department");

    //Conjunction query for must part of the Boolean query
    $mustConjunctsQuery = SearchQuery::conjuncts(
        $firstQuery,
        $secondQuery
    );

    //Boolean query
    $booleanQuery = SearchQuery::boolean();
    $booleanQuery->must($mustConjunctsQuery);

    $query = new SearchQuery($indexName, $booleanQuery);
    $result = $this->getBucket()->query($query);

My dev environment:
PHP SDK 2.6.1 (libcouchbase runtime version => 2.10.3)
Server Version: Community Edition 6.5.0 build 4966

Am I doing something wrong in the query composition or is this a bug in the SDK?

Thank you,
Emir

3 Likes

The same bug occurs to me when from the PHP SDK (libcouchbase 2.10.6-1) I make a boolean query with “must not”.
If I launch the query to the API REST FTS of the couchbae server (POST localhost:8094/api/index/fts_shopping/query ) it works correctly.
Couchbase Server version 6.0.3 and 6.5.1

The FTS query:

{
"indexName": "fts_shopping",
"size": 5,
"fields": [
    "shop_id",
    "shop_start_date"
],
"sort": [
    "-shop_last_update"
],
 "query": {
 "must":{
 "conjuncts": [
        {
            "query": "shop_typ_id:1"
        },
        {
            "query": "sections:10"
        },
        {
            "query": "shop_open:1"
        },
        {
            "query": "shop_food:1"
        },
        {
            "query": "shop_last_update:<\"2020-10-06 00:00:00\""
        },
        {
            "query": "shop_last_update:>\"2020-07-06 14:00:00\""
        }

  ]
 },
"must_not": {
"disjuncts": [
    {"ids": ["shopping::12345678", "shopping::87654321"]
    }
    ]
}
 }
}

Thanks

1 Like