Is it possible to obtain full path the objects find by a query - jsonata

Suppose you have **[Colour = 'Purple'] query (see here) and you wished to find actual path to the resulting nodes as below:
[
Account.Order[0].Product[0].Description
Account.Order[0].Product[3].Description
]
Is this possible? Any functions that can achieve this?
Thanks in advance.

Related

Scan result of a aggregation

I wanted to see how many unique link that a user has posted for every user. Here is what I have come up so far
s.aggs.bucket('user_term', A('terms', field='user__id')).metric('url_count', A('value_count', field='link'))
However, I have yet found a way to iterate through that result. Is there a way for this?
This will not give you a unique count, just a number of docs with a value for that field, you want to use a cardinality instead:
s.aggs.bucket('users', 'terms', field='user.id').metric('url_count', 'cardinality', field='link')
r = s.execute()
for user in r.aggregations.users.buckets:
print(f'User {user.key} posted {user.url_count.value} links')
Hope this helps

How to efficiently generate a unique combination of first and last name given an array of full names

I'm having a bit of difficulty with a problem I'm having. I have an array of names like so:
[Brutananadilewski, Carl]
[Crews, Xander]
[Cartman, Eric]
[Rubio, Daniel]
[Daniels, Julie]
etc. etc.
What I need to do is to create a list of unique names from this list without having first and last names repeated. So I would have the following as a result:
[Brutananadilewski, Daniel]
[Crews, Erix]
[Cartman, Xander]
[Rubio, Carl]
[Jill, Daniels]
The problem I'm having is trying to do this efficiently. My first instint was to use permutation and here is a snippet from the ruby docs
a.permutation(2).to_a #=> [[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]]
The problem is having the following from that example [[1,2],[1,3]]
Theoretically if this was a first/last name this wouldnt work. I couldn't have this:
[Rubio Daniel, Rubio Julie, Rubio Eric]
Has anyone dealt with this before? I'm having an awfully hard time with efficiency and just getting it to work. Help would be appreciated thank you.
You can use transpose as mentioned by 3limin4tor, then shuffle and zip as mentioned by Dave Newton:
surnames, forenames = names.transpose
shuffled_forenames = forenames.shuffle
shuffled_names = shuffled_forenames.zip(surnames)
The desired outcome isn't entirely clear from the question, but if you're trying to create all combinations of first/last names and get a subset of those, you could also use product and uniq to get all the uniq combinations:
names = [
%w(Brutananadilewski Carl),
%w(Crews Xander),
%w(Cartman Eric),
%w(Rubio Daniel),
%w(Daniels Julie)
]
surnames, forenames = names.transpose
all_name_combos = forenames.product(surnames).uniq
You could then use shuffle and sample(INTEGER) to get a subset of those name combinations
all_name_combos.shuffle.sample(5)

Units of an elasticsearch query to get distance from arbitrary point to Geopoint

I have a django project which uses elasticsearch 6.5.3 to index products in a store with locations as GeoPoints. I am trying to query this index and also calculate distance between an arbitrary point, say user's location to each oh these results.
I am using elasticsearch_dsl and my code looks something like this:
search_query = search_query.script_fields(distance={
'script':{
'inline':"doc['location'].arcDistance(params.lat, params.lon)",
'params': {
'lat':user_loc.lat,
'lon':user_loc.lon
}
}
})
for result in search_query.execute():
print(result.distance)
Which gives me values that looks like:
[123456.456879123]
But I'm not sure about its units.
By using and online distance calculator in https://www.nhc.noaa.gov/gccalc.shtml,
which gives me the distance as ~123km,
It looks like value is in meters.
So:
1. Where can I find some definitive answers about its units?
Please point me to the relevant documentation for these methods.
I am also interested to know if there is a way to specify the units expected for the results in the method call.
2. Is there a better way to do this in python?
The units are those returned by the arcDistance method providing the value in your script.
The arc distance (in meters) of this geo point field from the provided lat/lon
The painless docs leave a lot to be desired (there appears to be no docs on this method in 6.5). The quote above was obtained from here: https://www.elastic.co/guide/en/elasticsearch/reference/2.3/modules-scripting.html
Additionally, they mention arcDistance caluclates meters here: https://www.elastic.co/guide/en/elasticsearch/reference/5.5/breaking_50_scripting.html
I'm not sure about the exact python API, but elasticsearch have Geo Distance Query:
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html
In: https://github.com/elastic/elasticsearch-dsl-py/issues/398 there's an example of python usage of ES API:
MyDocType.search().filter(
'geo_distance', distance='1000m', location={"lat": "40", "lon": "-74"}
)
The 'geo_distance' query is the easiest way to get a distance between two geo points indexed to elasticsearch. I thinking that you don't need to use scripting in order to achieve that.
Regarding the distance unit, as you suspected the default is meters. from:
https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#distance-units
Wherever distances need to be specified, such as the distance parameter in the Geo Distance Query), the default unit if none is specified is the meter.

Iterating over NEST Buckets

I am trying NEST out and it seems very nice, but I am having some trouble understanding some things.
The response is serialized to an hierarchy of objects. I would like to iterate over it and to create my own structure.
I would be able to do somethings like this (thanks to #Martijn Laarman, who helped me in the GitHub page):
var buckets = result.Aggs.Terms("level_1");
var term = buckets.Items[0].Terms("level_2");
It works, but I would like to have a generic algorithm that parses the response. To do that, I would like to get content independently of the query (if it used terms, range, etc). So I would like to do things like:
var buckets = result.Aggregrations["level_1"];
var term = buckets.Items[0].Aggreggation["level_2"];
Unfortunately the Aggregations collection returns Nest.Bucket and I can't do anything from there.
Is there any way that I can iterate over the result independently on how the query was formed?
Thanks!
For sake of completeness, I was not able to find any way to do so.
I created a parser using a mix of JObects and Dictionary and operated over the JSON response to generate the output I wanted.

VBA:Compare string with find function value

How to compare with case sensitive in find function?
Like
stringtxt = Range("A1:A10").Find(What:=stringtxt , Lookat:=xlWhole,MatchCase:=False)
Here suppose stringtxt="ABCD (abcd)"
AND in range one of the cells may have value like "ABCD (ABCD)"
I have to compare this with contents in range specified.
I tried adding like "UCase".Didn`t work.MatchCase i tried with both true and false values.Didnt work though.
Suggest me some better answers to compare.
One of the parameters to the Find method is a MatchCase parameter, as follows:
Think that should help you solve this problem.

Resources