Module to index and search MongoDB documents using Elasticsearch
require("e3po")
Motivation: I'd prefer MongoDB syntax to query and update Elasticsearch index
- comparison operators
- logical operators
- $exists
- $all
- $elemMatch
- $text (with { query, operator, minimum_should_match, boost, analyzer })
- $nearSphere (with point and $maxDistance as geo_distance)
- $geoWithin(with polygon as geo_polygon)
Query operators use Elasticsearch bool query
- fields operators (except $setOnInsert)
- array operators
Conditions operators available:
Update operators use Elasticsearch painless script
Modifiers are supported
$, $[] and $[<identifier>] operators are supported only with $set operator and without query selectors
e3po
const { Client } = require('elasticsearch')
const e3po = require('e3po')({
client: new Client({ host: '127.0.0.1:9200' }),
index: 'test',
type: 'test'
})
e3po.search - search using Elasticsearch query
e3po.search({
query: {},
sort: { _id: -1 },
skip: 0,
limit: 1,
projection: {}
})
e3po.find - search using MongoDB query
e3po.find({
query: {},
filter: {},
sort: { _id: -1 },
skip: 0,
limit: 1,
projection: {}
})
e3po.insert - create index
e3po.insert({
body: { a: 1 }
})
e3po.upsert - create or update index
e3po.upsert({
id: '1',
body: { a: 1 }
})
e3po.update - update index
e3po.update({
id: '1',
body: { a: 2 }
)
e3po.remove - delete index
e3po.remove({
id: '1'
})
e3po.updateByScript - update index using Elasticsearch painless script and MongoDB update operators
e3po.updateByScript({
id: '1',
body: {
$set: {
a: 2
}
}
})
e3po.updateByQuery - update index by query using Elasticsearch painless script, MongoDB query operators and MongoDB update operators
e3po.updateByQuery({
query: {},
body: {
$set: {
a: 2
}
}
)
e3po.removeByQuery - delete index by query using MongoDB query operators
e3po.removeByQuery({
query: {}
})