Dong Nguyen
Meilisearch

Install

services:
  meilisearch:
    image: getmeili/meilisearch:v1.13.1
    container_name: meilisearch
    ports:
      - 0.0.0.0:7700:7700
    environment:
      MEILI_ENV: production #development
      MEILI_MASTER_KEY: ${YOUR_PASSWORD}
      MEILI_NO_ANALYTICS:
      MEILI_IGNORE_DUMP_IF_DB_EXISTS:
      MEILI_IGNORE_SNAPSHOT_IF_DB_EXISTS:
      MEILI_MAX_INDEXING_THREADS: 3
      MEILI_MAX_INDEXING_MEMORY: 4Gb
      MEILI_HTTP_PAYLOAD_SIZE_LIMIT: 100Mb
      MEILI_MAX_INDEX_SIZE: 2048MB
      MEILI_SCHEDULE_SNAPSHOT: 86400
    volumes:
      - ./storage/meili_data:/meili_data
    restart: unless-stopped
    
  meilisearch_ui:
    image: riccoxie/meilisearch-ui:v0.6.16
    container_name: meilisearch_ui
    ports:
      - 4900:4900
    restart: unless-stopped

Refs

Filters

List of supported operators

  • Equality: attribute = value

  • Inequality: attribute != value

  • Comparison:

    • attribute < value

    • attribute <= value

    • attribute > value

    • attribute >= value

    • attribute value TO value

  • Exists:

    • attribute EXISTS

    • attribute NOT EXISTS

  • IN:

    • attribute IN[value, value, etc.]

    • attribute NOT IN[value, value, etc.]

  • IS EMPTY:

    • attribute IS EMPTY

    • attribute IS NOT EMPTY

  • IS NULL:

    • attribute IS NULL

    • attribute IS NOT NULL

  • AND: filter AND filter

  • OR: filter OR filter

  • NOT: NOT filter

  • GeoSearch: _geoRadius(lat, lng, distance)

  • GeoSearch: _geoBoundingBox([lat, lng], [lat, lng])

Combining filter conditions

Note that AND has a higher precedence than OR. Therefore, the following filter:

x = 1 AND y = 2 OR z = 3

will be interepreted as:

(x = 1 AND y = 2) OR (z = 3)

Sample data:

[{
    "id": 0,
    "size": [0, "small"]
    "colour": "blue"
},
{
    "id": 1,
    "size": 1
},
{
    "id": 2,
    "size": [2, 20]
}]

The following filters will select these documents:

size = 0 OR size = 1                       -> selects [0,1]
size = 0 AND (size = 2 OR colour = "blue") -> selects []
size = 0 AND size = 2 OR colour = "blue"   -> selects [0]
size > 5 AND size < 5                      -> selects [2]

Negating a filter

The negation operator, NOT, is used to select all documents that are not selected by a sub-filter. It is a prefix operator that takes one argument. Its precedence is higher than both AND and OR.

With the same documents given as examples for the comparison operators, the following filters will select these documents:

NOT size = 0                               -> selects [1,2]
NOT (size = 0 OR size = 1)                 -> selects [2]
NOT size = 0 OR size = 1                   -> selects [1,2]
NOT (size < 2 AND colour = "blue")         -> selects [1,2]
NOT size < 2 AND colour = "blue"           -> selects []
size = 0 OR NOT size = 2                   -> selects [0,1]
NOT (NOT size = 0)                         -> selects [0]

EXISTS

The EXISTS operator selects the documents for which the filterable attribute exists, even if its value is null or an empty array. It is a postfix operator that takes an attribute name as argument.

The negated form of EXISTS can be written in two ways:

attribute NOT EXISTS
NOT attribute EXISTS

Both forms are equivalent. They select the documents for which the attribute does not exist.

For example, with the documents:

[{
    "id": 0,
    "colour": []
},
{
    "id": 1,
    "colour": null
},
{
    "id": 2
}]

Then the filter colour EXISTS selects the document ids [0,1] while the filter colour NOT EXISTS or NOT colour EXISTS selects the document ids [2]

IN

The IN[..] operator is a more concise way to combine equality operators. It is a postfix operator that takes an attribute name on the left hand side and an array of values on the right hand side. An array of value is a comma-separated list of values delimited by square brackets.

The two filters below are equivalent:

attribute IN[value1, value2, value3,]

attribute = value1 OR attribute = value2 OR attribute = value3

In short, IN selects the documents for which:

  1. the filterable attribute exists; and

  2. the attribute contains a value that is equal to any of the values in the array

The negated form of IN can be written in two different ways:

attribute NOT IN [value1, value2, etc.]
NOT attribute IN [value1, value2, etc.]

and it is equivalent to:

attribute != value1 AND attribute != value2 AND ...

IS EMPTY

The IS EMPTY operator selects the documents for which the filterable attribute exists and is empty. If the attribute doesn't exists then it is not empty and the document will not be returned. It is a postfix operator that takes an attribute name as argument.

The negated form of IS EMPTY can be written in two ways:

attribute IS NOT EMPTY
NOT attribute IS EMPTY

Both forms are equivalent. They select the documents for which the attribute is not empty.

Here is the list of JSON values that are considered empty:

  • ""

  • []

  • {}

For example, with the documents:

[{
    "id": 0,
    "colour": []
},
{
    "id": 1,
    "colour": null
},
{
    "id": 2,
    "colour": ""
},
{
    "id": 3,
    "colour": {}
},
{
    "id": 4
}]

Then the filter colour IS EMPTY selects the document ids [0,2,3] while the filter colour IS NOT EMPTY or NOT colour IS EMPTY selects the document ids [1,4].

IS NULL

The IS NULL operator selects the documents for which the filterable attribute exists and is null. If the attribute doesn't exists then it is not null and the document will not be returned. It is a postfix operator that takes an attribute name as argument.

The negated form of IS NULL can be written in two ways:

attribute IS NOT NULL
NOT attribute IS NULL

Both forms are equivalent. They select the documents for which the attribute is not null.

For example, with the documents:

[{
    "id": 0,
    "colour": []
},
{
    "id": 1,
    "colour": null
},
{
    "id": 2,
    "colour": ""
},
{
    "id": 3,
    "colour": {}
},
{
    "id": 4
}]

Then the filter colour IS NULL selects the document ids [1] while the filter colour IS NOT NULL or NOT colour IS NULL selects the document ids [0,2,3,4].

Array Syntax

The array syntax is an alternative way to combine different filters with OR and AND operators.

  • Elements in the outer array are connected by AND operators

  • Elements in the inner arrays are connected by OR operators

Example:

{
    "filter": [
    	["genres = Comedy", "genres = Romance"], 
    	"director = 'Mati Diop'"
    ]
}

is equivalent to:

{
    "filter": "(genres = Comedy OR genres = Romance) AND (director = 'Mati Diop')"
}