Dodawanie
PUT http://localhost:9200/books/book/1 HTTP/1.1 User-Agent: Fiddler Content-Type: application/json Host: localhost:9200 Content-Length: 175 { "title": "Parallel Worlds: A Journey Through Creation, Higher Dimensions, and the Future of the Cosmos", "author": "Michio Kaku", "year": "2006", "price": "12.06" }
Dodaliśmy zasób do kolekcji books. Zasób jest typu book. Na końcu dodajemy unikalny identyfikator. Jeżeli chcemy, by serwer ElasticSearch wygenerował za nas Id wysyłamy żądanie typu POST pod adres /books/book/.
Pobieranie
Aby pobrać zasób po identyfikatorze wysyłamy żądanie typu GET.
GET http://localhost:9200/books/book/1 HTTP/1.1 User-Agent: Fiddler Content-Type: application/json Host: localhost:9200
W odpowiedzi otrzymujemy JSON w następującej postaci:
HTTP/1.1 200 OK Content-Type: application/json; charset=UTF-8 Content-Length: 259 {"_index":"books","_type":"book","_id":"1","_version":1,"exists":true, "_source" : { "title": "Parallel Worlds: A Journey Through Creation, Higher Dimensions, and the Future of the Cosmos", "author": "Michio Kaku", "year": "2006", "price": "12.06" }}
Modyfikacja
Do modyfikacji wykorzystujemy POST, gdzie w body podajemy "ścieżkę" do property, które chcemy zmodyfikować.
POST http://localhost:9200/books/book/1/_update HTTP/1.1 User-Agent: Fiddler Content-Type: application/json Host: localhost:9200 Content-Length: 57 { "script": "ctx._source.author = \"Kaku, Michio\"" }
Usuwanie
Do usunięcia wykorzystuje się czasownik DELETE.
DELETE http://localhost:9200/books/book/1/ HTTP/1.1 User-Agent: Fiddler Content-Type: application/json Host: localhost:9200
Ponowne wysłanie GET'a pod powyższy adres zwraca kod HTTP 404.
Brak komentarzy:
Prześlij komentarz