Query by a field
Define searchable fields
You can define which fields should be saved to the index by marking them in the related content type at the chosen field's definition.
It is also possible to switch off indexing for certain content types. In that case nobody will be able to find the instances made with those content types using queries, and the index will be smaller.
About the possible indexing configurations and field definition see the schema and the content type concepts.
Basically query by a field works by adding the chosen field name to the query with a value that you are looking for:
query=[FieldName]:[value]
Field names are always case sensitive but values are not. The following queries return the same result:
query=Name:saturn
query=Name:SaTUrn
In the following examples you will see how you can query by the most common fields.
Query by a text field
The following query returns the content that's Color
is Yellow
GET https://example.com/OData.svc/Root?query=Color:Yellow
Following query returns the content that's DisplayName
field contains the word 'Astra' (notice that it is actually a wildcard search)
GET https://example.com/OData.svc/Root?query=DisplayName:*Astra*
Query by a number field
Following example shows how to get the list of cars that's Price
lower than 1 000 000:
GET https://example.com/OData.svc/Root?query=Price:<1000000
Query by a boolean field
You can also query by a boolean field as it is shown in the following example. The query returns the list of folders (e.g. content that's IsFolder
field's value is true
).
GET https://example.com/OData.svc/Root?query=InFolder:/Root/Content/Cars AND IsFolder:true
Query by choice field (localized value)
It is also possible to query by a choice field. Since choice options could have a value and the (localized) title you have to format your query according to which one you want to search for. See the following choice field's options
<Field name="MemoType" type="Choice"><DisplayName>Memo</DisplayName><Configuration><Options><Option value="generic" selected="true">Generic</Option><Option value="iso">ISO</Option><Option value="iaudit">Internal audit</Option></Options></Configuration></Field>
In the following example you can see that if you simply use a verb as a possible value of a choice field it will search for it as a choice option's text, in this case for 'Internal audit' memos.
GET https://example.com/OData.svc/Root?metadata=no&query=MemoType:'Internal audit'
Query by choice field (value)
If you use localized titles for the choice options you may need to query by value that is common even if the title could be used and displayed in various languages. In this case you have to use the '$' sign with the value.
GET https://example.com/OData.svc/Root?query=Style:$roadster