The Strapi documentation is apparently silent on this, unless I am missing something. The examples shown there only query the fields by string or numeric values.
What I have tried myself that didn't work:
http://localhost:1337/restaurants?vegan=true
http://localhost:1337/restaurants?vegan=1
http://localhost:1337/restaurants?vegan=0
http://localhost:1337/restaurants?vegan=null
I understand this is tricky because who's to say that true doesn't mean the literal string "true". So how do I query boolean fields' value via the API endpoint?
To answer your question, using the query param as true or false like you mentioned above works fine in strapi.
The problem you might be facing is how the default Boolean values are stored in the database. If you are using MYSQL databse with strapi , I checked the boolean type field is stored as TINYINT, and even if you select the default value as FALSE or TRUE while adding a new boolean field for a CONTENT-TYPE from UI, it is stored as null in the database (which i think is a bug in strapi, it should be 0 or 1 and not null). Refer the images below
So as a workaround, when adding a new record for your content-type, select the boolean field as ON, and save it, and once the record is saved you can edit the record (if you want the boolean value to be false) and save it as OFF. This would change the value to 0 in the database and you can then search the record through api endpoint using true or false. For eg http://localhost:1337/restaurants?vegan=true or http://localhost:1337/restaurants?vegan=false.
Related
I would like to perform an elasticsearch query relying on a GET request.
This query successfully allow me to see all the messages inside the index addressed to a particular sender (i.e., where sender.id == some value).
http://localhost:9200/myindex/messages/_search?q=sender.id:user1
Now, I would like to add a new field. In my case study, to retrieve only the messages with the boolean flag received set to true. So I tried:
http://localhost:9200/myindex/messages/_search?q=sender.id:user1&received:true
But this doesn't work, and I can't find any documentation / example on how to perform a GET query with multifield.
Please note that the parameter received exists, is always set, and is correctly working when used alone.
The q parameter take the lucene query syntax.
So to add another condition use the following:
http://localhost:9200/myindex/messages/_search?q=sender.id:user1%20AND%20received:true
Im having problems getting a query to return the results i require. Im wanting to search for all documents which have a Field name called 'Title' but only them where the value is null.
By default Elasticsearch does not store fields with null value in its index, so you are not able to distinguish documents without Title field at all from documents where this field contains null. To cope with this issue you have explicitly choose some value that will indicate that field is empty. Look at this article for details.
I have a type with a field indicating if to reveal another field. For example, for a document, if ifRevealAge is true, value of the age field should be retrieved from _source and included in query result for the document. If ifRevealAge is false, then age field should not be included in the query result for the document. Is it possible by query API?
If it is not, how to do it through java API? I think the method toXContent(XContentBuilder builder, ToXContent.Params params) of GetResponse is supposed to do so but I can't find any documentation or references for how to use the method for filtering / modifying response result conditionally. The api documentation is just too concise.
Many thanks
Im trying filter records with that has a specific value key and delete them. I tried "withFields" and "hasFields" but seems that i can't apply delete to them. My question is how can i do that?
r.db('databaseFoo').table('checkpoints').filter(function (user) {
return user('type').default(false);
}).delete();
If you want all documents that have a type key, you can use hasFields for that.
r.db('databaseFoo').table('checkpoints')
.hasFields('type')
In your current query, what you are doing is getting all documents that don't have a type key or where the value for type is equal to false. This might be what you want, but it's a little confusing if you only want documents that have a type property.
Keeping a reference to the original document
The problem with using hasFields is that it converts a selection (a sequence with a reference to the specific rows in the database) that you can update, and delete into a sequence, with which you can't do that. This is a known issue in RethinkDB. You can read this blog post to understand the different types in ReQL a bit better.
In order to get around this, you can use the hasFields method with the filter method.
r.db('databaseFoo').table('checkpoints')
.filter(r.row.hasFields('type'))
.delete()
This query will work since it returns a selection which can then be passed into delete.
If you want to get all records with with a specific value at a specific key, you can do so a couple of different ways. To get all documents where the property type is equal to false, you can do as follows:
r.db('databaseFoo').table('checkpoints')
.filter({ type: false })
or, you can do:
r.db('databaseFoo').table('checkpoints')
.filter(r.row('type').eq(false))
I want to implement a search for a solr filed when from view a checkbox is clicked
what parameter should I send?
My solr store is as follows
boolean :from_vendor do
!from_vendor?
end
Where from_vendor is boolean attribute in the table, I want to exclude from_vendor => true from my search, so I must search by false value as a search param, so that the shebang(!) sign can be avoided in the store.
Not sure what should I send as the search param, because the logic is, splitting up the param string , and based upon that assign condition to it, like, if I send params as
"0,+" , it means solr will search for all with value greater than 0. now In my case how should I construct my params?
Thanks in advance.