I have a field mapping defined as
{"top_seller":{"type":"boolean"}}
In my query, I'm trying to do a custom score query based on the boolean value. I'm pulling my hair out. Every time I run a script such as this:
return if(doc['top_seller'].value==true) {10} else {0}
Every single document gets the true 10 boost. Only 1% of my documents are set as TRUE. I've tried without ==true, with =='true'. I've tried the ternary. doc['top_seller'].value==true?10:0. I've tried 1/0 instead of true/false.
I even did an experiment where I created a new index and type with with a single true and a single false document. In a match_all query, they both get the boost as though they have the true value.
Wow, on a whim, I was looking at the core type settings for boolean.
The boolean type Maps to the JSON boolean type. It ends up storing within the index either T or F, with automatic translation to true and false respectively.
The answer is:
doc['top_seller'].value == 'T' ? 10 : 0
Edit: As of 5.2.x, I am finally able to use doc['top_seller'] ? 10 : 0. https://www.elastic.co/guide/en/elasticsearch/reference/current/boolean.html
Related
I've seen the JSON array questions here and I'm still a little lost, so could use some extra help.
Here's the setup:
My Flow calls a sproc on my DB and that sproc returns this JSON:
{
"ResultSets": {
"Table1": [
{
"OrderID": 9518338,
"BasketID": 9518338,
"RefID": 65178176,
"SiteConfigID": 237
}
]
},
"OutputParameters": {}
}
Then I use a PARSE JSON action to get what looks like the same result, but now I'm told it's parsed and I can call variables.
Issue is when I try to call just, say, SiteConfigID, I get "The output you selected is inside a collection and needs to be looped over to be accessed. This action cannot be inside a foreach."
After some research, I know what's going on here. Table1 is an Array, and I need to tell PowerAutomate to just grab the first record of that array so it knows it's working with just a record instead of a full array. Fair enough. So I spin up a "Return Values to Virtual Power Agents" action just to see my output. I know I'm supposed to use a 'first' expression or a 'get [0] from array expression here, but I can't seem to make them work. Below are what I've tried and the errors I get:
Tried:
first(body('Parse-Sproc')?['Table1/SiteConfigID'])
Got: InvalidTemplate. Unable to process template language expressions in action 'Return_value(s)_to_Power_Virtual_Agents' inputs at line '0' and column '0': 'The template language function 'first' expects its parameter be an array or a string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#first for usage details.'.
Also Tried:
body('Parse-Sproc')?['Table1/SiteconfigID']
which just returns a null valued variable
Finally I tried
outputs('Parse-Sproc')?['Table1']?['value'][0]?['SiteConfigID']
Which STILL gives me a null-valued variable. It's the worst.
In that last expression, I also switched the variable type in the return to pva action to a string instead of a number, no dice.
Also, changed 'outputs' in that expression for 'body' .. also no dice
Here is a screenie of the setup:
To be clear: the end result i'm looking for is for the system to just return "SiteConfigID" as a string or an int so that I can pipe that into a virtual agent.
I believe this is what you need as an expression ...
body('Parse-Sproc')?['ResultSets']['Table1'][0]?['SiteConfigID']
You can see I'm just traversing down to the object and through the array to get the value.
Naturally, I don't have your exact flow but if I use your JSON and load it up into Parse JSON step to get the schema, I am able to get the result. I do get a different schema to you though so will be interesting to see if it directly translates.
I am trying to get max & sum of two columns in a filter expression using MapboxGL-js. The two columns of interest may contain nulls.
Tried this for addition and it does not work (nothing shows up on the map)
["+",["to-number",['get', "col1"]],["to-number",['get', "col2"]]]
For max,I tried this and does not work either.
["max",["to-number",['get', "col1"]],["to-number",['get', "col2"]]]
Any suggestions? Thanks!
The filter defined in mapboxgl-js is
filter is a property at the layer level that determines which features should be rendered in a style layer.
In official mapboxgl-js example you can see that in case condition is true the feature will be rendered:
"filter": ["==", "icon", symbol]
where "icon" is equal to symbol (a variable that is set to the selected feature's icon property).
In your example there are no conditional operation done.
In case you are trying to show the "sum" or "max" as a layer's "text-field", you should use it there and not in filter, and return string after completing your Math operations.
so it will be
"test-field": ["to-string", ["max",["to-number", ["get", "col1"]],["to-number", ["get", "col2"] ]]],
Link to Filter Doc
Link to Expressions Docs
Hope this helps
I am trying to make a new ssrs report:
There is a details group that prints lines from datasource detailsDS.
I also want to make a textbox in the footer(or anywhere, doesn't matter) where if there was any(or more than one) line in detailDS with value that equals "Red" that textbox should be set invisible.
I already tried:
iif(first(Fields!Color.Value, "detailsDS") = "Red", True, false)
of course this doesn't work because it only searches for first record and textbox is out of scope of details.
Is it possible to solve this in report layer?
EDIT:
Seems like lookup function is not supported for ms dynamics.
As B.Seberie noted, you could use the lookup function.
=IIF(Lookup("Red", Fields!Color.Value, Fields!Color.Value, "detailsDS") = "Red", True, False)
You would want to use your static value of "Red" for the first argument. This is the value that will be searched for.
The second argument is for the field in the dataset that you want to check for the first argument's (Arg1) value.
The third argument (Arg3) is the field to return when it finds Arg1 in Arg2 - in this case you can just use the same color field. If the color is found, it will be TRUE otherwise it will be FALSE.
I have this piece of code:
Db.DbDataSet.Tables["costallocations"]
.AsEnumerable()
.Where(Row => Row.Field<long>("callocid") == OldCostAllocationId)[0]["newid"]
And I'm getting the error above. In my opinion, it should work. How can I access the first record of the result set? There will be always only one hit, btw, therefore I use the 0.
Map Fuction
function(doc, meta) {
if (doc.login_timestamp) {
emit(dateToArray(doc.login_timestamp), doc.username);
}
}
Produces:
[2011,10,10,10,10,09] “scalabl3”
[2012,12,24,17,03,59] “scalabl3”
[2013,01,01,08,22,23] “scalabl3”
[2013,01,25,10,38,01] “tgrall”
[2013,01,25,11,02,32] “jzablocki”
[2013,02,01,11,02,32] “scalabl3”
How do I get just the records from 2013?
I tried
startkey=[2013]&endkey=[2013]
That doesn't work because by definition results must be greater than equal the start key AND less than the end key
What is the correct way to do this?
Since you have an array, you can specify arrays for start and end. So one of two ways that should work:
startkey=[2013]&endkey=[2014]
or
startkey=[2013]&endkey=[2013,99]
In the second example, you give a value greater than any you expect to see in a valid entry.