Open2

elasticsearch, meilisearchのリクエスト比較

mattakmattak

ElasticSearch

healthチェック

GET /_cat/health

INDEX作成

PUT /myindex
{
  "mappings": {
    "properties": {
      "name": { "type": "text" }
    }
  }
}
GET /_cat/indices

登録

PUT /myindex/pokemon/1
{
	"name": "Pidgeot"
}
PUT /myindex/sample/2
{
	"name": "Pikachu"
}

検索

GET /myindex/_search
{
  "query": {
    "match": {
      "name": {
        "query":"Bekachu",
        "fuzziness": "AUTO"
      }
    }
  }
}
{
  "took": 9,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 0.49510515,
    "hits": [
      {
        "_index": "myindex",
        "_type": "pokemon",
        "_id": "2",
        "_score": 0.49510515,
        "_source": {
          "name": "Pikachu"
        }
      }
    ]
  }
}
mattakmattak

Meilisearch

healthチェック

GET /health

Index作成

POST /indexes
{
   "uid": "myindex"
}

登録

POST /indexes/myindex/documents
[
  {"id":1,"name":"Pidgeot"},
  {"id":2,"name":"Pikachu"}
]

検索

POST /indexes/myindex/search
{
  "q": "Pi"
}
{
  "hits": [
    {
      "id": 1,
      "name": "Pidgeot"
    },
    {
      "id": 2,
      "name": "Pikachu"
    }
  ],
  "query": "Pi",
  "processingTimeMs": 0,
  "limit": 20,
  "offset": 0,
  "estimatedTotalHits": 2
}

snapshot

起動時にsnapshotディレクトリとsnapshot間隔 (60秒) を指定.

/bin/meilisearch --schedule-snapshot=60 --snapshot-dir snapshots/

指定時間たったら snapshots/data.ms.snapshot に記録が残る

--import-snapshot で指定して起動すると前回のデータが復旧できる

/bin/meilisearch \
  --schedule-snapshot=60 --snapshot-dir snapshots/ \
  --import-snapshot snapshots/data.ms.snapshot

dump

起動時にdumpディレクトリを指定

/bin/meilisearch --dump-dir dumps/

リクエストしてデータをdumpさせる

POST /dumps

{
  "taskUid": 2,
  "indexUid": null,
  "status": "enqueued",
  "type": "dumpCreation",
  "enqueuedAt": "2023-08-03T14:12:45.011900846Z"
}

dumpファイルを指定して起動

./meilisearch --import-dump /meili_data/dumps/20230803-141245017.dump