Fulltext
If a fulltext index exists, then /_api/simple/fulltext will use this index to execute the specified fulltext query.
Create fulltext index
creates a fulltext index
POST /_api/index#fulltext
Query Parameters
- collection-name (required): The collection name.
A JSON object with these properties is required:
- fields (string): an array of attribute names. Currently, the array is limited to exactly one attribute.
- type: must be equal to "fulltext".
- minLength: Minimum character length of words to index. Will default to a server-defined value if unspecified. It is thus recommended to set this value explicitly when creating the index.
NOTE Swagger examples won't work due to the anchor.
Creates a fulltext index for the collection collection-name, if it does not already exist. The call expects an object containing the index details.
Example:
Creating a fulltext index
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/index?collection=products <<EOF
{
"type" : "fulltext",
"fields" : [
"text"
]
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
x-content-type-options: nosniff
{
"fields" : [
"text"
],
"id" : "products/10422",
"isNewlyCreated" : true,
"minLength" : 2,
"sparse" : true,
"type" : "fulltext",
"unique" : false,
"error" : false,
"code" : 201
}
Return Codes
- 200: If the index already exists, then a HTTP 200 is returned.
- 201: If the index does not already exist and could be created, then a HTTP 201 is returned.
- 404: If the collection-name is unknown, then a HTTP 404 is returned.
Examples
Creating a fulltext index
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/index?collection=products <<EOF
{
"type" : "fulltext",
"fields" : [
"text"
]
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
x-content-type-options: nosniff
{
"fields" : [
"text"
],
"id" : "products/10422",
"isNewlyCreated" : true,
"minLength" : 2,
"sparse" : true,
"type" : "fulltext",
"unique" : false,
"error" : false,
"code" : 201
}
shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/index?collection=products <<EOF
{
"type" : "fulltext",
"fields" : [
"text"
]
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
x-content-type-options: nosniff
Fulltext index query
returns documents of a collection as a result of a fulltext query
PUT /_api/simple/fulltext
A JSON object with these properties is required:
- index: The identifier of the fulltext-index to use.
- attribute: The attribute that contains the texts.
- collection: The name of the collection to query.
- limit: The maximal amount of documents to return. The skip is applied before the limit restriction. (optional)
- skip: The number of documents to skip in the query (optional).
- query: The fulltext query. Please refer to Fulltext queries for details.
This will find all documents from the collection that match the fulltext query specified in query.
In order to use the fulltext operator, a fulltext index must be defined for the collection and the specified attribute.
Returns a cursor containing the result, see Http Cursor for details.
Note: the fulltext simple query is deprecated as of ArangoDB 2.6. This API may be removed in future versions of ArangoDB. The preferred way for retrieving documents from a collection using the near operator is to issue an AQL query using the FULLTEXT AQL function as follows:
FOR doc IN FULLTEXT(@@collection, @attributeName, @queryString, @limit)
RETURN doc
Example:
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/fulltext <<EOF
{
"collection" : "products",
"attribute" : "text",
"query" : "word"
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
x-content-type-options: nosniff
{
"result" : [
{
"_key" : "10738",
"_id" : "products/10738",
"_rev" : "_VTxTKE2---",
"text" : "this text contains word"
},
{
"_key" : "10742",
"_id" : "products/10742",
"_rev" : "_VTxTKE2--_",
"text" : "this text also has a word"
}
],
"hasMore" : false,
"count" : 2,
"error" : false,
"code" : 201
}
Return Codes
- 201: is returned if the query was executed successfully.
- 400: is returned if the body does not contain a valid JSON representation of a query. The response body contains an error document in this case.
- 404: is returned if the collection specified by collection is unknown. The response body contains an error document in this case.
Examples
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/fulltext <<EOF
{
"collection" : "products",
"attribute" : "text",
"query" : "word"
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
x-content-type-options: nosniff
{
"result" : [
{
"_key" : "10738",
"_id" : "products/10738",
"_rev" : "_VTxTKE2---",
"text" : "this text contains word"
},
{
"_key" : "10742",
"_id" : "products/10742",
"_rev" : "_VTxTKE2--_",
"text" : "this text also has a word"
}
],
"hasMore" : false,
"count" : 2,
"error" : false,
"code" : 201
}
shell> curl -X PUT --data-binary @- --dump - http://localhost:8529/_api/simple/fulltext <<EOF
{
"collection" : "products",
"attribute" : "text",
"query" : "word"
}
EOF
HTTP/1.1 201 Created
content-type: application/json; charset=utf-8
x-content-type-options: nosniff