Skip to content

Commit

Permalink
feat(elasticsearch): improve mappings - EUBFR-88 (#55)
Browse files Browse the repository at this point in the history
* feat(elasticsearch): add mappings

* feat(elasticsearch): add mappings

* Remove google shortener
  • Loading branch information
kalinchernev authored Dec 13, 2017
1 parent 34fdb1e commit 8a67c11
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 31 deletions.
3 changes: 2 additions & 1 deletion services/ingestion/etl/agri/csv/src/lib/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export default (record: Object): Project => {
country_name: null,
country_code: country,
location: {
// elasticsearch specific structure for geo_point https://goo.gl/nbi2Yp
// elasticsearch specific structure for geo_point
// read more https://www.elastic.co/guide/en/elasticsearch/reference/5.5/modules-scripting-expression.html#_literal_geo_point_literal_field_api
lat: (Array.isArray(latArray) && latArray[index]) || 0,
lon: (Array.isArray(longArray) && longArray[index]) || 0,
},
Expand Down
2 changes: 1 addition & 1 deletion services/value-store/elasticsearch/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ resources:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
# Admin access to Kibana from an IP
# https://goo.gl/eiGgpD
# http://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-kibana.html?shortFooter=true
- Effect: Allow
Principal: "*"
Action: es:*
Expand Down
2 changes: 1 addition & 1 deletion services/value-store/projects/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ provider:
stackTags:
ENV: ${self:custom.eubfrEnvironment}
iamRoleStatements:
# https://goo.gl/U21zxP
# http://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-aws-integrations.html?shortFooter=true#es-aws-integrations-s3-lambda-es-authorizations
- Effect: "Allow"
Action: "es:*"
Resource: "arn:aws:es:${self:provider.region}:*:domain/*"
Expand Down
33 changes: 5 additions & 28 deletions services/value-store/projects/src/events/onObjectCreated.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import split2 from 'split2';

import deleteProjects from '../lib/deleteProjects';
import SaveStream from '../lib/SaveStream';
// elasticsearch mapping https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html
import ProjectMapping from '../mappings/project';

export const handler = (event, context, callback) => {
const { API, INDEX } = process.env;
Expand Down Expand Up @@ -45,33 +47,6 @@ export const handler = (event, context, callback) => {
index: INDEX,
};

// elasticsearch mapping overrides/corrections
// the rest of the fields are dynamically discovered fine for now
const body = {
project: {
properties: {
project_locations: {
properties: {
location: {
type: 'geo_point',
ignore_malformed: true,
},
},
},
timeframe: {
properties: {
from: {
type: 'date',
},
to: {
type: 'date',
},
},
},
},
},
};

// elasticsearch client instantiation
const client = elasticsearch.Client(options);

Expand All @@ -84,7 +59,9 @@ export const handler = (event, context, callback) => {
return exists;
})
.then(() => client.indices.getMapping({ index: INDEX, type }))
.catch(() => client.indices.putMapping({ index: INDEX, type, body }))
.catch(() =>
client.indices.putMapping({ index: INDEX, type, body: ProjectMapping })
)
.then(() =>
s3
.headObject({
Expand Down
50 changes: 50 additions & 0 deletions services/value-store/projects/src/mappings/project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module.exports = {
project: {
properties: {
budget: {
properties: {
funding_area: {
type: 'keyword',
},
},
},
computed_key: {
type: 'keyword',
},
coordinators: {
properties: {
country: {
type: 'keyword',
},
},
},
ec_priorities: {
type: 'keyword',
},
producer_id: {
type: 'keyword',
},
programme_name: {
type: 'keyword',
},
project_locations: {
properties: {
location: {
type: 'geo_point',
ignore_malformed: true,
},
},
},
timeframe: {
properties: {
from: {
type: 'date',
},
to: {
type: 'date',
},
},
},
},
},
};

0 comments on commit 8a67c11

Please sign in to comment.