Skip to content

Instantly share code, notes, and snippets.

import json
import openai
from elasticsearch import Elasticsearch
from elasticsearch.helpers import bulk
es = Elasticsearch(
[{'host': 'localhost', 'port': 9200, 'scheme': 'http'}])
openai.api_key = 'key'
[
{"code": 1, "title": "The Shawshank Redemption", "genre": ["Drama"], "director": "Frank Darabont", "actors": ["Tim Robbins", "Morgan Freeman", "Bob Gunton", "William Sadler"], "description": "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.", "year": 1994, "runtime": "142 min", "rating": 9.3, "votes": 2343110, "revenue": "28,341,469", "metascore": 80, "certificate": "A", "avatar": "https://m.media-amazon.com/images/M/MV5BMDFkYTc0MGEtZmNhMC00ZDIzLWFmNTEtODM1ZmRlYWMwMWFmXkEyXkFqcGdeQXVyMTMxODk2OTU@._V1_UX67_CR0,0,67,98_AL_.jpg"}
,
{"code": 2, "title": "The Godfather", "genre": ["Crime", "Drama"], "director": "Francis Ford Coppola", "actors": ["Marlon Brando", "Al Pacino", "James Caan", "Diane Keaton"], "description": "An organized crime dynasty's aging patriarch transfers control of his clandestine empire to his reluctant son.", "year": 1972, "runtime": "175 min", "rating": 9.2, "votes": 1620367, "revenue": "134,966,411", "metascore": 100,
{"index":{}}
{"name":"Mercedes-benz C 180","category":"Cars and Motorcycle/Cars and Vans/Mercedes-Benz/Class C"}
{"index":{}}
{"name":"Honda Fit 1.5 LX","category":"Cars and Motorcycle/Cars and Pickup truck/Honda/Fit"}
{"index":{}}
{"name":"Honda City Sedan DX","category":"Cars and Motorcycle/Cars and Pickup truck/Honda/City"}
{"index":{}}
{"name":"Mercedes-Benz Sprinter Van","category":"Cars and Motorcycle/Cars and Vans/Mercedes-Benz/Sprinter Van"}
{"index":{}}
{"name":"Sprinter Van 2.2 Cdi","category":"Cars and Motorcycle/Cars and Vans/Mercedes-Benz/Sprinter Van"}
{
"coordinates": [
[
[
-63.170695,
-5.7905056
],
[
-63.1679484,
-5.7946045
{"coordinates": [
[
[
-62.9015375,
-4.8826388
],
[
-62.9248835,
-4.8894803
],
POST test/_doc
{
"category_suggest": {
"input": [
"Automotive",
"Auto"
]
}
}
package javahighclient.searchafter;
import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;
import javahighclient.RestClientUtils;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
{
"settings": {
"analysis": {
"analyzer": {
"en_analyzer": {
"tokenizer": "standard",
"filter": [
"lowercase","stop" ]
},
"shingle_analyzer": {
{"index": {}}
{"code": 1, "title": "The Shawshank Redemption", "title_suggest": ["The", "Shawshank", "Redemption"], "genre": ["Drama"], "director": "Frank Darabont", "actors": ["Tim Robbins", "Morgan Freeman", "Bob Gunton", "William Sadler"], "description": "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.", "year": 1994, "runtime": "142 min", "rating": 9.3, "votes": 2343110, "revenue": "28,341,469", "metascore": 80, "certificate": "A", "avatar": "https://m.media-amazon.com/images/M/MV5BMDFkYTc0MGEtZmNhMC00ZDIzLWFmNTEtODM1ZmRlYWMwMWFmXkEyXkFqcGdeQXVyMTMxODk2OTU@._V1_UX67_CR0,0,67,98_AL_.jpg"}
{"index": {}}
{"code": 2, "title": "The Godfather", "title_suggest": ["The", "Godfather"], "genre": ["Crime", "Drama"], "director": "Francis Ford Coppola", "actors": ["Marlon Brando", "Al Pacino", "James Caan", "Diane Keaton"], "description": "An organized crime dynasty's aging patriarch transfers control of his clandestine empire to his reluctant son.
#! Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/7.17/security-minimal-setup.html to enable security.
{
"took" : 8,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},