FTS Boolean Field Query JSON API

Hey gyus,

i have an index containing boolean fields. (declared in index as boolean)
Now i want to query for these boolean fields with JSON query against the available Couchbase REST Api Url.
Term querys and all the rest works fine, but i am not able to successfully query my boolean fields. :frowning:

My last try looks like this:

{
“explain”: false,
“fields”: [
"*"
],
“highlight”: {},
“query”: {
“bool” : true,
“field” : “positions.items.released”
},
“facets”: {
“country”: {
“size”: 100,
“field”: “positions.items.tasks.content.country”
}
},
“size”: 5,
“from”: 0
}

But it doesn’t work.
Error message is: err: unknown query type

If i try it this way

“query”: {
“bool” : “true”,
“field” : “positions.items.released”
},

i also get the error message: err: unknown query type

Maybe sbd. has a hint? THX

Also querying over nodejs couchbase api doesn’t work.

Here my example:

var SearchQuery = couchbase.SearchQuery;
var bFieldQuery = new SearchQuery.BooleanFieldQuery(true);
bFieldQuery.field = ‘positions.items.released’;

var query = SearchQuery.new(‘bwewid’, bFieldQuery);

var config = nconf.get(‘couchbase:bwewidCredentials’);
var cluster = new couchbase.Cluster(config.host);
bucket = cluster.openBucket(config.bucket, config.password);

bucket.query(query, function (err, res, meta) {
if(err){
console.log(err);
}

if (res) {
    for (var i = 0; i < res.length; ++i) {
        console.log('Hit:', res[i].id);
    }
}

});

err response:
[Error: An FTS error occured: rest_index: Query, indexName: bwewid, requestBody: {“ctl”:{“timeout”:75000},“indexName”:“bwewid”,“query”:{“data”:{“bool”:true},“field”:“positions.items.released”}}
, req: &http.Request{Method:“POST”, URL:(*url.URL)(0xc8273a0080), Proto:“HTTP/1.1”, ProtoMajor:1, ProtoMinor:1, Header:http.Header{“User-Agent”:[]string{“libcouchbase/2.6.2”}, “Accept”:[]string{“application/json”}, “Authorization”:[]string{“Basic Yndld2lkOmNoYW5nZW1l”}, “Content-Length”:[]string{“113”}, “Content-Type”:[]string{“application/json”}}, Body:(*http.body)(0xc828430040), ContentLength:113, TransferEncoding:[]string(nil), Close:false, Host:“ec2-52-57-43-22.eu-central-1.compute.amazonaws.com:8094”, Form:url.Values{}, PostForm:url.Values{}, MultipartForm:(*multipart.Form)(nil), Trailer:http.Header(nil), RemoteAddr:“77.74.239.22:22896”, RequestURI:"/api/index/bwewid/query", TLS:(*tls.ConnectionState)(nil), Cancel:(<-chan struct {})(nil)}, err: alias: QueryAlias parsing searchRequest, req: {“ctl”:{“timeout”:75000},“indexName”:“bwewid”,“query”:{“data”:{“bool”:true},“field”:“positions.items.released”}}
, err: unknown query type
]

Hi Andre,
You found a bug in 4.5. Your query should work but I verified that it doesn’t. You can track the progress of this bug here: MB-21018

There is a workaround that you can use right now in 4.5, although it’s not guaranteed to work in a later release version. Because Boolean values are indexed internally as the terms T and F, you can do a term search for those single, upper case characters. Any type of search that perform analysis won’t work, however, so stick with a term query to be safe. Here’s an example that should work for you:

{
  "explain": false,
  "fields": [
    "*"
  ],
  "highlight": {},
  "query": {
    "term": "T",
    "field": "positions.items.released",
    "boost": 1.0
  }
}

Thanks for pointing that out.

Best,
-Will

THX, its working. :slight_smile: