I was following the ElasticSearch guide online to represent coordinates as "lat, lng" but it doesnt seem to be working until I flip everything around to "lng, lat". I even have to flip around top_left and bottom_right in order for the query to work.
Is anyone experiencing the same problem? Clearly this is not how the documentation says to use it, but it's only working when I format it this way.
Rails format
def self.search(params)
tire.search( page: params[:page], per_page: 2 ) do
query { all }
filter :geo_bounding_box, location: { top_left: " -121.88596979687497, 37.33588487375733", bottom_right: " -122.43528620312497, 37.553946238118264" }
end
end
CURL format
curl -X GET "http://localhost:9200/articles/article/_search?page=&per_page=2&size=2&pretty=true" -d '{"query":{"match_all":{}},"facets":{"condition":{"terms":{"field":"condition","size":10,"all_terms":false}}},"filter":{"geo_bounding_box":{"location":{"top_left":" -121.88596979687497, 37.33588487375733","bottom_right":" -122.43528620312497, 37.553946238118264"}}},"size":2}'
Console response
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 169,
"max_score" : 1.0,
"hits" : [ {
"_index" : "articles",
"_type" : "article",
"_id" : "4f72bc7d0bdb820f02000002",
"_score" : 1.0, "_source" : {"content":"words here!","location":[37.444995,-122.160628],"name":"harro"}
}, {
"_index" : "articles",
"_type" : "article",
"_id" : "4fdf0cf20bdb82336c000002",
"_score" : 1.0, "_source" : {"content":"Run of the mill","location":[37.33588487375733,-121.88596979687497],"name":"Billy Bob"}
} ]
},
"facets" : {
"condition" : {
"_type" : "terms",
"missing" : 5597,
"total" : 0,
"other" : 0,
"terms" : [ ]
}
}
When geo point is specified as a string, it should be in "lat,lon" format. When it is specified as an array, it should be in [lon, lat] format.
Related
I'm using neo4j with spring data, when I store an object with inside a relation I get as a result of the findAll a corrupted json. I never get this error when I query the objects one at time.
Even more strange the first one in the list is correct but the second has this error. The error is at the edge field. Any idea?
[{
"uuid" : "e5c90af5-6259-4ddf-ae1f-c0cff5a41296",
"name" : "test",
"createdBy" : {
"uuid" : "319535cc-288f-4a23-bc02-a3b01bf6e93f",
"createdAt" : "2017-03-10T02:06:55.925+0000",
"user" : {
"uuid" : "9e91032e-a54d-4297-8a6a-1506589b7529",
},
"edge" : { "id" : 6514
},
"graphId" : 664
}
},
{
"uuid" : "e5c90af5-6259-4ddf-ae1f-c0cff5a41296",
"name" : "test",
"createdBy" : {
"uuid" : "319535cc-288f-4a23-bc02-a3b01bf6e93f",
"createdAt" : "2017-03-10T02:06:55.925+0000",
"user" : {
"uuid" : "9e91032e-a54d-4297-8a6a-1506589b7529",
},
"edge" : { : 6514
},
"graphId" : 664
}
}]
I want to sort my query results following some boost rules and in the same time i want them to be sorted as possible by creation date, if i add a created_at sort, it changes everything and my results are not relevant anymore. So i guess the only way to do that is to boost created_at field (the newest has the biggest bonus in calculating score for that boost) but i dont know how to implement it. This is my query:
query = {
"query" : {
"bool" : {
"must" : [
{
"range" : {
"deadline" : {
"gte" : "2016-05-30T11:39:10+02:00"
}
}
},
{
"terms" : {
"state" : [
"open"
]
}
},
{
"query_string" : {
"query" : "chant",
"default_operator" : "AND",
"analyzer" : "search_francais",
"fields" : [
"title^6",
"description",
"brand",
"category_name"
]
}
}
]
}
},
"filter" : {
"and" : [
{
"geo_distance" : {
"distance" : "40km",
"location" : {
"lat" : 48.855736,
"lon" : 2.32927300000006
}
}
}
]
},
"sort" : [
{
"_score" : "desc"
},
#{
# "created_at" : "desc" ==> i tried this but it doesnt change results
#}
]
}
Try adding your condition in should block.
i)If the created date should be closer to come value in the search query or you have any idea on how close the date should be, give a range query.
ii) If you are not sure of all those values, decay function can be used. In this case, query shall be changed to function query.
{
"query" : {
"bool" : {
"must" : [
{
"range" : {
"deadline" : {
"gte" : "2016-05-30T11:39:10+02:00"
}
}
},
{
"terms" : {
"state" : [
"open"
]
}
},
{
"query_string" : {
"query" : "chant",
"default_operator" : "AND",
"analyzer" : "search_francais",
"fields" : [
"title^6",
"description",
"brand",
"category_name"
]
}
}
],
"should": [
{"created_at" : "condition here .. "}
]
}
},
"filter" : {
"and" : [
{
"geo_distance" : {
"distance" : "40km",
"location" : {
"lat" : 48.855736,
"lon" : 2.32927300000006
}
}
}
]
}
}
Is it possible to create Salesreceipt without product/service value through QBO API? I have tried through API but it's not reflecting rate value and storing description value only.
If I remove ItemRef attribute(in request body) then it's reflecting rate and amount values and it's assigning some default and random product/service.
It is possible directly in QBO UI.
Request body where only description value storing:
{
"TxnDate" : "2016-05-27",
"Line" : [ {
"Amount" : 2222.00,
"Description" : "hi chk",
"DetailType" : "ItemReceiptLineDetail",
"ItemReceiptLineDetail" : {
"ItemRef" : { },
"Qty" : 1,
"UnitPrice" : 2222
} }
],
"CustomerRef" : {
"value" : "67"
},
"CustomerMemo" : {
"value" : "Thanks for your business! We appreciate referrals!"
},
"TotalAmt": 2222.00,
"PrivateNote" : "",
"CustomField" : [ {
"DefinitionId" : "1",
"Type" : "StringType",
"StringValue" : ""
} ]
}
Request body where default product/service assigning:
{
"TxnDate" : "2016-05-27",
"Line" : [ {
"Amount" : 2222.00,
"Description" : "hi chk",
"DetailType" : "ItemReceiptLineDetail",
"ItemReceiptLineDetail" : {
"Qty" : 1,
"UnitPrice" : 2222
} }
],
"CustomerRef" : {
"value" : "67"
},
"CustomerMemo" : {
"value" : "Thanks for your business! We appreciate referrals!"
},
"TotalAmt": 2222.00,
"PrivateNote" : "",
"CustomField" : [ {
"DefinitionId" : "1",
"Type" : "StringType",
"StringValue" : ""
} ]
}
No.
QuickBooks Online does not support this.
I have some Rails models that are indexed in Elasticsearch (via Tire gem). I can index new documents and query the existing index.
What I can't seem to do is get ahold of the highlight attached to a record from within my Rails app. I can however see that highlight is returned in the json when I interact with Elasticsearch directly via curl.
When I try to access the highlight property of my record I get: undefined method 'highlight' for #<Report:0x007fe8afa54700>
# app/views/reports/index.html.haml
%h1 Listing reports
...
- #reports.results.each do |report|
%tr
%td= report.title
%td= raw report.highlight.attachment.first.to_s
But if I use curl I can see the highlight is returned to Tire...
$ curl -X GET "http://localhost:9200/testapp_development_reports/report/_search?load=true&pretty=true" -d '{query":{"query_string":{"query":"contains","default_operator":"AND"}},"highlight":{"fields":{"attachment":{}}}}'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 0.111475274,
"hits" : [ {
"_index" : "testapp_development_reports",
"_type" : "report",
"_id" : "1",
"_score" : 0.111475274, "_source" : {"id":1,"title":"Sample Number One",...,"attachment":"JVBERi0xMJ1Ci... ...UlRU9GCg==\n"},
"highlight" : {
"attachment" : [ "\nThis <em>contains</em> one\n\nodd\n\n\n" ]
}
}, {
"_index" : "testapp_development_reports",
"_type" : "report",
"_id" : "2",
"_score" : 0.111475274, "_source" : {"id":2,"title":"Number two",...,"attachment":"JVBERi0xLKM3OA... ...olJVPRgo=\n"},
"highlight" : {
"attachment" : [ "\nThis <em>contains</em> two\n\neven\n\n\n" ]
}
} ]
}
}
The search method in the model:
...
def self.search(params)
tire.search(load: true) do
query { string params[:query], default_operator: "AND" } if params[:query].present?
highlight :attachment
end
end
...
Method highlight is inaccessible when you are using load: true option. This should be fixed in future versions of Tire.
edit: you can use each_with_hit method to access returned elasticsearch values now
For example:
results = Article.search 'One', :load => true
results.each_with_hit do |result, hit|
puts "#{result.title} (score: #{hit['_score']})"
end
You can find my answer right at this post
Elasticsearch/Lucene highlight
My method works fine for me and wish you can get it work as well.
I have Coordinate model with many markers embedded_in User model. How to extract attributes without _ids so that on output display only each lng and lat?
structure:
{ "_id" : ObjectId( "4e9f418f1e7bf20fbc000009" ),
"name" : "test",
"coordinates" : [
{ "lng" : 16.86783310009764,
"lat" : 52.38353842845282,
"_id" : ObjectId( "4e9f418f1e7bf20fbc00000a" ) },
{ "lng" : 16.85787674023436,
"lat" : 52.40972501601293,
"_id" : ObjectId( "4e9f418f1e7bf20fbc00000b" ) },
{ "lng" : 16.92276474072264,
"lat" : 52.40071858320756,
"_id" : ObjectId( "4e9f418f1e7bf20fbc00000c" ) },
{ "lng" : 16.90182205273436,
"lat" : 52.38270020105396,
"_id" : ObjectId( "4e9f418f1e7bf20fbc00000d" ) },
{ "lng" : 16.96705337597655,
"lat" : 52.410661698108,
"_id" : ObjectId( "4e9f418f1e7bf20fbc00000e" ) },
{ "lng" : 16.89495559765624,
"lat" : 52.42773236584494,
"_id" : ObjectId( "4e9f418f1e7bf20fbc00000f" ) } ] }
e.g.
= debug #user.coordinates.to_json
gives:
--- ! '[{"_id":"4e9f418f1e7bf20fbc00000a","lat":52.383538428452816,"lng":16.86783310009764},{"_id":"4e9f418f1e7bf20fbc00000b","lat":52.40972501601293,"lng":16.85787674023436},{"_id":"4e9f418f1e7bf20fbc00000c","lat":52.40071858320756,"lng":16.92276474072264},{"_id":"4e9f418f1e7bf20fbc00000d","lat":52.382700201053964,"lng":16.90182205273436},{"_id":"4e9f418f1e7bf20fbc00000e","lat":52.410661698108,"lng":16.967053375976548},{"_id":"4e9f418f1e7bf20fbc00000f","lat":52.42773236584494,"lng":16.894955597656235}]'
expected:
--- ! '[{"lat":52.383538428452816,"lng":16.86783310009764},{"lat":52.40972501601293,"lng":16.85787674023436},{"lat":52.40071858320756,"lng":16.92276474072264},{"lat":52.382700201053964,"lng":16.90182205273436},{"lat":52.410661698108,"lng":16.967053375976548},{"lat":52.42773236584494,"lng":16.894955597656235}]'
Try using except
#user.coordinates.to_json(:except => '_id')
the accepted answer returns data you wished. I would suggest though to use without against mongoid query so you actually do not fetch the data from DB, which is ideal.
#user.coordinates.without('_id').to_json(:except => '_id')