Skip to content

Instantly share code, notes, and snippets.

{ "query": { "bool": {
"must": [
{"term": {"description.text": "beard"}}
],
"should": [
{"term": {"description":"bearded"}}
]
}}}
@starakaj
starakaj / mapping.json
Last active May 10, 2017 14:41
Adding a mapping for the field description on the type object
"mappings": {
"object": {
"description": {
"type": "text",
"fields": {
"text": { "type": "text", "analyzer": "text_description_analyzer" }
}
}
}
}
"text_description_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"english_stop",
"english_stemmer"
]
}
{ "query": { "bool": { "must": [
{"term": {"description": "beard"}}
]}}}
const elasticsearch = require('elasticsearch');
const objectData; // Assume this JSON representing an object in the collection
const client = new elasticsearch.Client({ host: 'localhost:9200' });
client.create({
index: 'collection',
type: 'object',
id: objectData.id,
create table collection(
id bigint unsigned primary key,
name varchar(100),
description varchar(512)
);
insert into collection (id, name, description) values
(1, 'Two Geese', 'A painting of two beautiful geese'),
(2, 'Roses in Bloom', 'Blooming roses, obviously'),
(3, 'Still Life with Cake', 'A partially eaten cake, next to a vase.');
@starakaj
starakaj / gist:cfb1d8ef6eb933457035d59adcac879a
Created May 10, 2017 13:55
Creating a simple collection table
create table collection(
id bigint unsignet primary key,
name varchar(100),
description varchar(512)
);
insert into collection (id, name, description) values
(1, 'Two Geese', 'A painting of two beautiful geese'),
(2, 'Roses in Bloom', 'Blooming roses, obviously'),
(3, 'Still Life with Cake', 'A partially eaten cake, next to a vase.');
@starakaj
starakaj / csvWriter.js
Created April 12, 2017 17:51
Writing a CSV
const logger = require('./logger.js');
const fs = require('fs');
const csv = require('fast-csv');
module.exports = class CSVWriter {
constructor(path) {
logger.info(`Opening CSV file at ${path}`);
this._path = path;
this._csvStream = csv.createWriteStream({ headers: true });
this._writableStream = fs.createWriteStream(path);
@starakaj
starakaj / tmsURLReader.js
Created April 12, 2017 17:44
URL for a collection object by ID
// from src/tms_csv/src/script/tmsURLReader.js
_urlForObjectWithId(id) {
const requestURL = url.parse(this.rootURL);
requestURL.pathname = `objects/${id}/json`;
this._addCredentialsToURL(requestURL);
return url.format(requestURL);
}
@starakaj
starakaj / tmsURLReader.js
Created April 12, 2017 17:43
Fetching an Art Object
_fetchArtObjectWithId(id) {
const requestURLString = this._urlForObjectWithId(id);
logger.info(`Fething collection object with id: ${id} at url: ${requestURLString}`);
return new Promise((resolve, reject) => {
const req = https.request(requestURLString, (res) => {
let data = '';
res.on('data', (d) => {