Query DSL¶
Nixiesearch has a Lucene-inspired query DSL with multiple search operators.
To search over a field, make sure that this field is marked as searchable in index mapping.
Search operators¶
Currently three search operators are supported:
- match: search over a single field
- multi_match: search over multiple fields
- match_all: match all documents
All search operators can be combined with filters to search over a subset of documents.
match¶
Match query can be written in two JSON formats. A full version:
{
"query": {
"match": {
"<field-name>": {
"query": "<search-query>",
"operator": "or",
"threshold": 0.666
}
}
}
}
{
"query": {
"match": {
"<field-name>": "<search-query>"
}
}
}
Where:
<field-name>
: is an existing field marked as searchable.<search-query>
: a search query string.operator
: optional, possible values:"and"
,"or"
. Default is "or". For lexical search, should documents contain all or some of the terms from the search query. For semantic search this parameter is ignored.threshold
: optional, a cosine similarity threshold
multi_match¶
An operator similar to match but able to search multiple fields at once:
{
"query": {
"multi_match": {
"fields": ["<field-name>", "<field-name>"],
"query": "<search-query>",
"operator": "and"
}
}
}
Where:
<field-name>
: is an existing field marked as searchable.<search-query>
: a search query string.operator
: optional, possible values:"and"
,"or"
. For lexical search, should documents contain all or some of terms from the search query. For semantic search this parameter is ignored.
Compared to Lucene-based search engines, Nixiesearch does a RRF mixing of documents matched over different fields:
- At first pass, documents matching each separate field are collected.
- At next step N separate per-field search results are merged together into a single ranking.
This approach allows mixing search results made over multiple fields of different underlying search types, e.g. combining lexical and semantic search over N fields.
match_all¶
A search operator matching all documents in an index. Useful when combining with filters to search over a subset of documents.
{
"query": {
"match_all": {}
}
}
match_all
operator has no parameters.
Wildcard field queries¶
To allow more dynamism in index schema, you can use *
wildcard placeholder in field names:
schema:
movies:
extra_*:
type: text
search:
type: lexical
language: en
So all fields matching the wildcard pattern are going to be treated according to the schema. Wildcard fields have minor limitations:
- only a single
*
placeholder is allowed. - you cannot have a non-wildcard field defined matching a wildcard pattern (e.g. having both a regular
title_string
field and a wildcard*_string
in the same index).
To search over a wildcard field, you have to use the exact field name:
{
"query": {
"match": {
"extra_title": "<search-query>"
}
}
}
Although it's possible to use wildcard placeholders in retrieval fields:
{
"query": {
"match_all": {}
},
"fields": ["extra_*"]
}
Which will return all fields stored for a document matching the extra_*
wildcard pattern.