:orphan:
.. role:: json(code)
:language: json
.. role:: python(code)
:language: python
Search API
==========
.. contents:: :depth: 3
Skeleton
########
Examples
--------
.. code:: xml
{{ request.GET.phrase }}
123456
{{ 123456 }}
123456
{{ request.GET.phrase }}
article,image,video
path/to/section-1,{{ 12345678 }}
path/to/section-3,path/to/section/that/does/not/exist
path.to.field1=value1,path.to.field2=value2
path.to.field3=value3
{{ request.GET.another_phrase }}
tag-1
tag-2,tag-3
Endpoints
#########
Get Indexes
-----------
.. code::
GET /core/v1/search/indexes
200 OK
******
.. code:: json
{
"indexes": [
{
"slug": "my-first-index",
"title": "My First Index",
"status": "created",
"mapping":
]
}
Hints:
* (see: `Mappings`_)
Create/Modify Index
-------------------
.. code::
PUT /core/v1/search/indexes/
.. code:: json
{
"commands": [
,
,
...
]
}
200 OK
******
.. code:: json
{
"indexes": [
{
"slug": "my-second-index",
"title": "My Second Index",
"status": "created",
"mapping":
]
}
Hints:
- (see: `Commands`_)
- (see: `Mappings`_)
Fill Index with Data
--------------------
.. code::
POST /core/v1/search/indexes/my-second-index/index-posts
.. code::
POST /core/v1/search/indexes/my-second-index/index-users
.. code::
GET /core/v1/search/indexes/my-second-index/index-posts?task_id=38e9eea7-fc5b-4373-90f0-cb2d59109113
.. code::
GET /core/v1/search/indexes/my-second-index/index-users?task_id=38e9eea7-fc5b-4373-90f0-cb2d59109113
200 OK
******
.. code:: json
{
"task": {
"id": "38e9eea7-fc5b-4373-90f0-cb2d59109113",
"is_ready": true,
"progress": null, // or same as "response"
"response": {
"entities": {
"total_count": 12343,
"indexed_count": 12343
}
},
"exception": null
}
Find records count
------------------
.. code::
POST core/v1/search/indexes/my-second-index/find-count
.. code:: json
{
"filters": [
,
,
...
]
}
200 OK
******
.. code:: json
{
"records_count": 41234
}
Hints:
- (see: `Filters`_)
Find records
------------
.. code::
POST core/v1/search/indexes/my-second-index/find
.. code:: json
{
"filters": [
,
,
...
],
"chunk": {
"order": ,
"limit": 10,
"offset": 0,
"cursor":
}
}
200 OK
******
.. code:: json
{
"records": [
{"id": , "cursor": "cursor-1"},
{"id": , "cursor": "cursor-2"},
...
]
}
Hints:
- (see: `Filters`_)
- (see: `Orders`_)
- (see: :ref:`taxonomy-entity-guids`)
Commands
########
The commands allow to navigate an index through its lifecycle:
#. Create index
* Update index title
:json:`{"set-title": "My Second Index"}`
* Update index mapping:
:json:`{"set-mapping": }`
#. Start index. It’s not possible to change the mapping after an index is started
:json:`{"start": {}}`
* Fill the index with data
#. Activate index. It makes it available for reads
:json:`{"activate": {}}`
* Use index for searching
#. Stop index. It’s not possible to read or write from it anymore but the data is still stored
:json:`{"stop": {}}`
#. Remove index. It removes the index with all its data
:json:`{"remove": {}}`
Hints:
- (see: `Mappings`_)
Mappings
########
.. code:: json
{
"root": ,
"texts": [
{
"weight": 8,
"analyzer": ,
"extractor": ,
},
...
],
"shapes": [
{
"alias": "alias-for-the-geo-point",
"extractor": {"geo_point": {
"latitude": {"basic": {"field": {"post-custom-field": {"path": "location.latitude"}}}},
"longitude": {"basic": {"field": {"post-custom-field": {"path": "location.longitude"}}}}
}}
},
...
],
"values":[
{"type": , "field": },
{"type": , "field": },
...
],
"labels": [
{"field": },
{"field": },
...
],
"filters": [
,
,
...
]
}
Hints:
- (see: :ref:`taxonomy-entity-types`)
- (see: `Text Analyzers`_)
- (see: `Text Extractors`_)
- (see: `Value Types`_)
- (see: :ref:`taxonomy-entity-fields`)
- (see: :ref:`taxonomy-filters`)
Text Analyzers
--------------
Text analysis is the process of converting unstructured text, like the body
of an email or a product description, into a structured format that’s optimized
for search.
- For full-text search
:json:`{"unicode": {}}`
- For full-text search by English words
:json:`{"english": {}}`
- For exact case-insensitive search by words
:json:`{"keyword": {"normalizers": [{"lowercase": {}}]}}`
- For search by a case-insensitive substring with the length at least of 3 symbols (tri-gram tokens)
:json:`{"ngram": {"size": 3, "normalizers": [{"uppercase": {}}]}}`
Text Extractors
---------------
Text extraction is the process of retrieving and combining texts from indexed
entities. This text then goes through text analysis process before being stored
in the index.
- Take an entity text as it is
:json:`{"basic": {"field": }}`
- Combine text from a sequence of sub-extractors
.. code:: json
{
"composite": {
"extractors": [
,
,
...
],
}
}
- Extract text based on a condition
.. code:: json
{
"conditioned": {
"condition": {"taxonomy": {"filters": [
,
,
...
]}},
"then_extractor": ,
"else_extractor":
}
}
Hints:
- (see: :ref:`taxonomy-entity-fields`)
- (see: :ref:`taxonomy-filters`)
Value Types
-----------
Value fields used for both sorting results as well as filtering by range.
Therefore, it can only support some simple types:
- Strings
:json:`"str"`
- Numbers
:json:`"int"`
- Numbers with floating point
:json:`"float"`
Filters
#######
- Include only records that match the phrase with default syntax and text weights
.. code:: json
{
"phrase": {
"phrase": "Hello World"
}
}
- Include only records that match the `strict syntax `_ query only in the 2nd text field
.. code:: json
{
"phrase": {
"phrase": "\"Hello World\"",
"syntax": {"strict": {}},
"weights": [0, 10, 0]
}
}
- Include only records that match
.. code:: json
{
"geo-distance": {
"shape": "alias-from-the-mapping",
"point": {"latitude": "37.7749", "longitude": "-122.4194"},
"radius": {"miles": "1000.0"}
}
}
- Include only records that match labels and ranges
.. code:: json
{
"taxonomy":
}
Hints:
- (see: :ref:`taxonomy-filters`)
Orders
######
- Sort by one of the value fields
:json:`{"value": {"field": , "reverse": true}}`
- Sort by relevance to the phrase
:json:`{"relevance": {}}`
- Sort by relevance to the phrase penalizing "older" records relevance score
:json:`{"relevance": {"decay": {"field": }}}`
- Sort by distance to the point
:json:`{"geo-distance": {"shape": "alias-from-the-mapping", "point": {"latitude": "37.7749", "longitude": "-122.4194"}}, "reverse": false}`
Hints:
- (see: :ref:`taxonomy-entity-fields`)