Skip to content

Latest commit

 

History

History
291 lines (239 loc) · 6.92 KB

File metadata and controls

291 lines (239 loc) · 6.92 KB
curl \
  -X POST 'MEILISEARCH_URL/indexes/movies/documents?primaryKey=id' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer aSampleMasterKey' \
  --data-binary @movies.json
// With npm:
// npm install meilisearch

// Or with yarn:
// yarn add meilisearch

// In your .js file:
// With the `require` syntax:
const { MeiliSearch } = require('meilisearch')
const movies = require('./movies.json')
// With the `import` syntax:
import { MeiliSearch } from 'meilisearch'
import movies from './movies.json'

const client = new MeiliSearch({
  host: 'http://localhost:7700',
  apiKey: 'aSampleMasterKey'
})
client.index('movies').addDocuments(movies)
  .then((res) => console.log(res))
# In the command line:
# pip3 install meilisearch

# In your .py file:
import meilisearch
import json

client = meilisearch.Client('http://localhost:7700', 'aSampleMasterKey')

json_file = open('movies.json', encoding='utf-8')
movies = json.load(json_file)
client.index('movies').add_documents(movies)
/**
 * Using `meilisearch-php` with the Guzzle HTTP client, in the command line:
 *   composer require meilisearch/meilisearch-php \
 *     guzzlehttp/guzzle \
 *     http-interop/http-factory-guzzle:^1.0
 */

/**
 * In your PHP file:
 */
<?php

require_once __DIR__ . '/vendor/autoload.php';

use Meilisearch\Client;

$client = new Client('http://localhost:7700', 'aSampleMasterKey');

$movies_json = file_get_contents('movies.json');
$movies = json_decode($movies_json);

$client->index('movies')->addDocuments($movies);
// For Maven:
// Add the following code to the `<dependencies>` section of your project:
//
// <dependency>
//   <groupId>com.meilisearch.sdk</groupId>
//   <artifactId>meilisearch-java</artifactId>
//   <version>0.15.0</version>
//   <type>pom</type>
// </dependency>

// For Gradle
// Add the following line to the `dependencies` section of your `build.gradle`:
//
// implementation 'com.meilisearch.sdk:meilisearch-java:0.15.0'

// In your .java file:
import com.meilisearch.sdk;
import java.nio.file.Files;
import java.nio.file.Path;

Path fileName = Path.of("movies.json");
String moviesJson = Files.readString(fileName);
Client client = new Client(new Config("http://localhost:7700", "aSampleMasterKey"));
Index index = client.index("movies");
index.addDocuments(moviesJson);
# In the command line:
# bundle add meilisearch

# In your .rb file:
require 'json'
require 'meilisearch'

client = MeiliSearch::Client.new('http://localhost:7700', 'aSampleMasterKey')

movies_json = File.read('movies.json')
movies = JSON.parse(movies_json)

client.index('movies').add_documents(movies)
// In the command line:
// go get -u github.com/meilisearch/meilisearch-go

// In your .go file:
package main

import (
  "os"
  "encoding/json"
  "io"

  "github.com/meilisearch/meilisearch-go"
)

func main() {
  client := meilisearch.New("http://localhost:7700", meilisearch.WithAPIKey("masterKey"))

  jsonFile, _ := os.Open("movies.json")
  defer jsonFile.Close()

  byteValue, _ := io.ReadAll(jsonFile)
  var movies []map[string]interface{}
  json.Unmarshal(byteValue, &movies)

  _, err := client.Index("movies").AddDocuments(movies, nil)
  if err != nil {
      panic(err)
  }
}
// In the command line:
// dotnet add package Meilisearch

// In your .cs file:
using System.IO;
using System.Text.Json;
using Meilisearch;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace Meilisearch_demo
{
    public class Movie
    {
        public string Id { get; set; }
        public string Title { get; set; }
        public string Poster { get; set; }
        public string Overview { get; set; }
        public IEnumerable<string> Genres { get; set; }
    }

    internal class Program
    {
        static async Task Main(string[] args)
        {
            MeilisearchClient client = new MeilisearchClient("http://localhost:7700", "aSampleMasterKey");
            var options = new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true
            };

            string jsonString = await File.ReadAllTextAsync("movies.json");
            var movies = JsonSerializer.Deserialize<IEnumerable<Movie>>(jsonString, options);

            var index = client.Index("movies");
            await index.AddDocumentsAsync<Movie>(movies);
        }
    }
}
// In your .toml file:
  [dependencies]
  meilisearch-sdk = "0.29.1"
  # futures: because we want to block on futures
  futures = "0.3"
  # serde: required if you are going to use documents
  serde = { version="1.0",   features = ["derive"] }
  # serde_json: required in some parts of this guide
  serde_json = "1.0"



// In your .rs file:
// Documents in the Rust library are strongly typed
#[derive(Serialize, Deserialize)]
struct Movie {
  id: i64,
  title: String,
  poster: String,
  overview: String,
  release_date: i64,
  genres: Vec<String>
}

// You will often need this `Movie` struct in other parts of this documentation. (you will have to change it a bit sometimes)
// You can also use schemaless values, by putting a `serde_json::Value` inside your own struct like this:
#[derive(Serialize, Deserialize)]
struct Movie {
  id: i64,
  #[serde(flatten)]
  value: serde_json::Value,
}

// Then, add documents into the index:
use meilisearch_sdk::{
  indexes::*,
  client::*,
  search::*,
  settings::*
};
use serde::{Serialize, Deserialize};
use std::{io::prelude::*, fs::File};
use futures::executor::block_on;

fn main() { block_on(async move {
  let client = Client::new("http://localhost:7700", Some("aSampleMasterKey"));

  // Reading and parsing the file
  let mut file = File::open("movies.json")
    .unwrap();
  let mut content = String::new();
  file
    .read_to_string(&mut content)
    .unwrap();
  let movies_docs: Vec<Movie> = serde_json::from_str(&content)
    .unwrap();

  // Adding documents
  client
    .index("movies")
    .add_documents(&movies_docs, None)
    .await
    .unwrap();
})}
// Add this to your `Package.swift`
dependencies: [
  .package(url: "https://github.com/meilisearch/meilisearch-swift.git", from: "0.17.0")
]

// In your .swift file:
let path = Bundle.main.url(forResource: "movies", withExtension: "json")!
let documents: Data = try Data(contentsOf: path)
let client = try MeiliSearch(host: "http://localhost:7700", apiKey: "aSampleMasterKey")

client.index("movies").addDocuments(documents: documents) { (result) in
    switch result {
    case .success(let task):
        print(task)
    case .failure(let error):
        print(error)
    }
}
// In the command line:
// dart pub add meilisearch
// In your .dart file:
import 'package:meilisearch/meilisearch.dart';
import 'dart:io';
import 'dart:convert';
var client = MeiliSearchClient('http://localhost:7700', 'aSampleMasterKey');
final json = await File('movies.json').readAsString();
await client.index('movies').addDocumentsJson(json);