Skip to content

Instantly share code, notes, and snippets.

View quoeamaster's full-sized avatar

Q3Master quoeamaster

View GitHub Profile
@quoeamaster
quoeamaster / medium_querydsl_match_all
Created June 24, 2018 01:03
medium querydsl match_all
GET index_1/_search
{
"query": {
"match_all": {}
}
}
@quoeamaster
quoeamaster / medium_querydsl_match_all_size
Created June 24, 2018 01:12
medium queryDSL match_all (size)
GET index_1/_search
{
"size": 20,
"query": {
"match_all": {}
}
}
@quoeamaster
quoeamaster / medium_querydsl_match_all_sort
Created June 24, 2018 01:18
medium queryDSL match_all sorting
GET books_from_amazon/_search
{
"size": 20,
"query": {
"match_all": {}
},
"sort": [
{
"name.keyword": {
"order": "desc"
@quoeamaster
quoeamaster / medium_node_elastic_builder_00.js
Created July 3, 2018 06:37
example on using elastic-builder to build queryDSL
// Import the library
const eb = require('elastic-builder'); // the builder
// create the 'body' and add 'query' contents / conditions
const requestBody = new eb.RequestBodySearch()
.query(new eb.MatchQuery('product_desc', 'sports shoes yellow shoe laces'));
// get back the build json
//{
// "query": {
@quoeamaster
quoeamaster / medium_jq_example_00.js
Last active July 3, 2018 07:14
medium - client-side jquery library for es
// connect to a node (localhost:9200)
var client = new $.es.Client({
hosts: 'localhost:9200'
});
// run a simple query
client.search({
index: 'product_index',
type: 'doc',
body: {
@quoeamaster
quoeamaster / medium_node_example-00.js
Created July 3, 2018 07:13
medium - node example 00
// import the 'elasticsearch' package / library
var elasticsearch = require('elasticsearch');
// connect to a node (localhost:9200
var client = new elasticsearch.Client({
host: 'localhost:9200'
});
// run a query
client.search({
PUT imdb_nested
{
"mappings": {
"properties": {
"actors": {
"type": "nested",
"properties": {
"id": {
"type": "keyword"
},
POST imdb_nested/_bulk
{"index":{"_id":"re_1"}}
{"movie":{"year":2002,"img":"https://m.media-amazon.com/images/M/MV5BZmI1ZGRhNDYtOGVjZC00MmUyLThlNTktMTQyZGE3MzE1ZTdlXkEyXkFqcGdeQXVyNDE5MTU2MDE@._V1_UY268_CR1,0,182,268_AL_.jpg","name":"Resident Evil (2002)","duration":{"display":"1h 40min","in_min":100},"genre":["action","horror","sci-fi"],"genre_display":"action, horror, sci-fi","stars":6.7,"desc":"A special military unit fights a powerful, out-of-control supercomputer and hundreds of scientists who have mutated into flesh-eating creatures after a laboratory accident","director":"Paul W.S. Anderson"},"actors":[{"id":"act_001","name":"Milla Jovovich","avatar":"https://m.media-amazon.com/images/M/MV5BNzA1Nzc4NjYwNV5BMl5BanBnXkFtZTcwNjA2NjY1Mg@@._V1_UY317_CR18,0,214,317_AL_.jpg","home":"https://www.imdb.com/name/nm0000170/?ref_=tt_ov_st_sm"},{"id":"act_003","name":"Michelle Rodriguez","avatar":"https://m.media-amazon.com/images/M/MV5BYThkMmY1OTYtMTZmNi00YTVmLThkMGItNDlhNzE0ZDZkNGQ0XkEyXkFqcGdeQXVyMjQwMDg0Ng@@._V
POST _ingest/pipeline/_simulate
{
"pipeline": {
"description": "PRE-PROCESSING: add back last_update_time by using the ingest object",
"processors": [
{
"set": {
"field": "last_update_time",
"value": "{{_ingest.timestamp}}"
}
POST _ingest/pipeline/_simulate
{
"pipeline": {
"description": "any stage: add back last_update_time by script",
"processors": [
{
"script": {
"lang": "painless",
"source": """
def ts = new Date();