Elasticsearch: casting doubles to geo_point. Error with invalid geohash character - elasticsearch

I'm getting an error when I run this script to concatenate longitude and latitude doubles into a geo_point.
ElasticsearchIllegalArgumentException[the character \'.\' is not a valid geohash character]
Here's my script for reference:
mappings: {
'index': {
'transform': {
'lang': 'groovy',
'script': "ctx._source['coords'] = [ctx._source['lon'],ctx._source['lat']]"
}
'properties': {
'lon': {
'type': 'double',
},
'lat': {
'type': 'string',
},
'coords': {
'type': 'geo_point',
}
}
}
}
I'd appreciate any help, thanks!

Since you are extracting data from the source, you need to transform strings in to doubles in your groovy script:
new Double(ctx._source['lon']);

Related

Elastic 7.X Root mapping definition has unsupported parameters

After upgate from 6.X to 7.X
I got next error in index create
RequestError(400, 'mapper_parsing_exception',
'Root mapping definition has unsupported parameters:
[speechanalytics-transcript : {
properties={
transcript_operator={similarity=scripted_tfidf, type=text}}]')
query body is
{
'settings': {
'similarity': {
'scripted_tfidf': {
'type': 'scripted',
'script': {'source': 'double tf = doc.freq; return query.boost * tf;'},
},
},
},
'mappings': {
'speechanalytics-transcript': {
'properties': {
'transcript_operator':{
'type': 'text',
'analyzer': 'standard',
'similarity': 'scripted_tfidf',
}
}
}
}
}
In new version mapping type was removed
https://www.elastic.co/guide/en/elasticsearch/reference/6.7/removal-of-types.html
need to change mapping
'mappings': {
'speechanalytics-transcript': {
'properties': {
'transcript_operator':{
'type': 'text',
'analyzer': 'standard',
'similarity': 'scripted_tfidf',
}
}
}
}
to
'mappings': {
'properties': {
'transcript_operator':{
'type': 'text',
'analyzer': 'standard',
'similarity': 'scripted_tfidf',
}
}
}

AmCharts hide/ remove categoryField

https://snag.gy/9etSHc.jpg ----- this is the image link with what i need to remove.
const chart = this.AmCharts.makeChart( 'chartavaliacao' + id + idf,
{
'type': 'serial',
'theme': 'light',
'rotate': true,
'colors': colorScheme,
'dataProvider': this.dados,
'graphs': this.grafico,
'marginTop': 10,
'marginLeft': 15,
'marginBottom': 0,
'addClassNames': true,
'valueAxes':[{
'unit': '%',
'maximum': 100,
'minimum': 0,
}],
'categoryField': 'categoria', <<<<<<<<<<<<<<<<<< i need to remove this field from my graph
'titles': [
{
'id': 'Title-1',
'size': 15,
'text': this.grouped ? this.titulo : ''
}
],
'listeners': [{
'event': 'drawn',
'method': modifyAxis
}, {
'event': 'clickGraphItem',
'method': redireciona
}]
}, 10);
}
I need to remove from my graph 'categoryField' but if i comment this show UNDEFINED.
I tryed to put false and e got the same result.
someone can help with this question?
Not knowing what your modifyAxis code does, the safest possible way I can think of that will likely not interfere with it is to use a labelFunction that returns an empty string or single space:
AmCharts.makeChart(..., {
// ...
categoryAxis: {
labelFunction: function() {
return " ";
},
// ...
}
// ...
}

Mongoosastic: error sorting by distance

I am getting the following Elastic Search error when I try to sort search results by distance with Mongoosastic:
{ message: 'SearchPhaseExecutionException[Failed to execute phase
[query_fetch], all shards failed; shardFailures
{[rQFD7Be9QbWIfTqTkrTL7A][users][0]: SearchParseException[[users][0]:
query[filtered(+keywords:cafe)->GeoDistanceFilter(location,
SLOPPY_ARC, 25000.0, -70.0264952, 41.2708115)],from[-1],size[-1]:
Parse Failure [Failed to parse source
[{"timeout":60000,"sort":[{"[object Object]":{}}]}]]]; nested:
SearchParseException[[users][0]:
query[filtered(+keywords:cafe)->GeoDistanceFilter(location,
SLOPPY_ARC, 25000.0, -70.0264952, 41.2708115)],from[-1],size[-1]:
Parse Failure [No mapping found for [[object Object]] in order to sort
on]]; }]' }
See bellow for code sample:
var query = {
"filtered": {
"query": {
"bool": {
"must": [
{
"term": {
"keywords": "cafe"
}
}
]
}
},
"filter": {
"geo_distance": {
"distance": "25km",
"location": [
41.2708115,
-70.0264952
]
}
}
}
};
var opts = {
"sort": [
{
"_geo_distance": {
"location": [
41.2708115,
-70.0264952
],
"order": "asc",
"unit": "km",
"distance_type": "plane"
}
}
],
"script_fields": {
"distance": "doc[\u0027location\u0027].distanceInMiles(41.2708115, -70.0264952)"
}
};
User.search(query, opts, function (err, data) {
if (err || !data || !data.hits || !data.hits.hits || !data.hits.hits.length) {
return callback(err);
}
var total = data.hits.total,
//page = params.page || 1,
per_page = query.size,
from = query.from,
//to = from +
page = query.from / query.size,
rows = data.hits.hits || [];
for (var i = 0; i < rows.length; i++) {
rows[i].rowsTotal = total;
}
callback(err, toUser(rows, params));
});
Here is the User schema:
var schema = new Schema({
name: {type: String, default: '', index: true, es_type: 'string', es_indexed: true},
location: {type: [Number], es_type: 'geo_point', es_indexed: true, index: true},
shareLocation: {type: Boolean, default: false, es_type: 'boolean', es_indexed: true},
lastLocationSharedAt: {type: Date},
email: {type: String, default: '', index: true, es_type: 'string', es_indexed: true},
birthday: {type: String, default: ''},
first_name: {type: String, default: ''},
last_name: {type: String, default: ''},
gender: {type: String, default: ''},
website: {type: String, default: '', index: true, es_indexed: true},
verified: {type: Boolean, default: false},
});
I am also getting an error, I think the upgrade of Mongoosastic is double wrapping the code. It def seems to be based on 'sort' rather than on search but still reviewing. Val seems to have a better idea of what is going on as perhaps it has something to do with user schema rather than function.
I am using a similar schema and just upgraded and encountered issues.

GeoCode filter in mongoose elasticsearch

I am trying to do geo point filter in mongodb in meanjs. i have used mongoosastic modules but i am not able to perform geo point filter.
here below are the mongoose schema and controller code for filter.
Mongoose schema
'use strict';
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
mongoosastic = require('mongoosastic');
var BusinessSchema = new Schema({
name: {type: String, unique: 'Name already exists', trim: true, required: 'Name is required.', es_indexed: true},
searchTags: {type: [String], es_indexed: true},
alias: {type: Array, es_indexed: true},
// geoLocation: { type: [Number], /*/ [<longitude>, <latitude>]*/ index: '2d', /*/ create the geospatial index,*/ required: 'GeoLocation is required.', es_indexed:true,es_type:'geo_point'},
geo_cords: {
type: Array
},
address: {
address1: {type: String, required: 'Address is required', trim: true},
address2: String,
city: {type: String, required: 'City is required', trim: true},
// state: {type: String, required: 'State is required', trim: true},
country: {type: String, required: 'Country is required', trim: true},
postalCode: {type: String, required: 'Postal code is required', trim: true},
neighbourhood: String
},
isActive: {
type: Boolean,
default: true,
es_indexed: true
},
dateUpdated: {
type: Date
, es_indexed: true
},
dateCreated: {
type: Date,
default: Date.now
, es_indexed: true
}
});
controller code for filter and query
var mongoose = require('mongoose'),
Business = mongoose.model('Businesses');
var query = {
"query_string": {
"multi_match": {
"query": categoryIds.join(' OR '),
"fields": ["categoryIds", "relatedCategoryIds"]
}
},
"filter": {
"bool": {
"should": [
{"term": {"address.postalCode": "110016"}},
{"geo_distance": {
"distance": "50km",
"geo_cords": [-122.3050, 37.9174]
}
}
],
}
}
}
Business.search(query, function (err, results) {
// sendResponse(req, res, err, results)
if (!err) {
res.json(results);
} else {
res.status(400).send({message: 'Business Not Found'})
}
});
while doing this i am getting a long error saying
QueryParsingException[[businessess] failed to find geo_point field [geo_cords]
According to the documentation of mongoosastic
Geo mapping
Prior to index any geo mapped data (or calling the synchronize), the mapping must be manualy created with the createMapping (see above).
First, in your schema, define 'geo_cords' this way:
geo_cords: : {
geo_point: {
type: String,
es_type: 'geo_point',
es_lat_lon: true
},
lat: { type: Number },
lon: { type: Number }
}
Add an es_type: 'object' to each Array or embbeded type
alias: {type: Array, es_indexed: true, es_type: 'object'}
Then call .createMapping() on the model just after you've created it.

QueryParsingException failed to find geo_point field

I am getting QueryParsingException[[listings] failed to find geo_point field [location.coords]]; }] and can't quite figure out why.
My Query
esClient.search({
index: 'listings',
body: {
query: {
filtered: {
query: {
match_all: {}
},
filter: {
geo_distance: {
distance: '10km',
'location.coords': {
lat: parseFloat(query.point.lat),
lon: parseFloat(query.point.lon)
}
}
}
}
}
}
}, function(err, response) {
if(err) return console.log(err);
console.log(response);
});
My mapping (as you can see -yes, I did use geo_point type)
body: {
properties: {
location: {
type: 'object',
properties: {
country: {
type: 'integer'
},
address: {
type: 'string'
},
suburb: {
type: 'string'
},
coords: {
type: 'geo_point',
precision: '3m'
}
}
}
}
}
EDIT:
After looking up http://localhost:9200/listings/_mapping/my-mapping, I noticed the coords field have the lat, lon set to double - could this have something to do with it.
Ok so it turns out this was happening because of how I was defining the geo_point's precision (needs to be wrapped in fielddata property), oddly the JS api i'm using didn't throw any kind of error that I recall:
Correct:
coords: {
type: 'geo_point',
fielddata: {
format: 'compressed',
precision: '3m'
}
}
Incorrect:
coords: {
type: 'geo_point',
precision: '3m'
}
}
And voila...

Resources