I have a json of this type:
{
"_index": "indexeer",
"_type": "_doc",
"_id": "3233233233",
"_score": 1,
"_source": {
"Bibtex": {
"Article": {
"AuthorList": [
{
"Affiliation": {
"Affiliation": "Title content, Hematology and Hepatology Honorary Fellow, Honorary Member, American Society. xxxyyy#hotmail.com."
}
}
]
}
}
}
}
I get the Affiliation using jq like so:
jq -r '._source.Bibtex.Article.AuthorList[]? | .Affiliation.Affiliation | .[0:rindex(" Electronic address:")]' results.json
It works great, and gives me excatly the affiliations I need.
However, I now need the id field aswell and produce a csv like so:
"3233233233", "Title content, Hematology and Hepatology Honorary Fellow, Honorary Member, American Society"
I am able to get the ID seperately, easily like so:
jq -r '._id' results.json
but, how do I combine the two queries to produce a single output consisting of id and affiliation?
Essentially I want to combine the two queries.
Use [] to construct an array from your two elements and #csv to convert to CSV:
jq -r '[
._id,
._source.Bibtex.Article.AuthorList[]?.Affiliation.Affiliation[:rindex(" Electronic address:")]
] | #csv'
Output:
"3233233233","Title content, Hematology and Hepatology Honorary Fellow, Honorary Member, American Society. xxxyyy#hotmail.com."
Multiple authors will be added as columns to your CSV.
It's worth nothing that jq allows you to concatenate multiple arrays into a single one. Concatenating streams produces the cartesian product, e.g. [1]+[2] produces [1,2] and [1]+([2],[3]) will produce [1,2][1,3] (a stream comprising two arrays). You can leverage this fact to produce multiple output lines without capturing the id in a variable first:
[._id]
+ (._source.Bibtex.Article.AuthorList[]? | [ .Affiliation.Affiliation[0:rindex(" Electronic address:")] ])
| #csv
Save the id as a variable using ._id as $id, then you can use $id where ever you like:
._id as $id | ._source.Bibtex.Article.AuthorList[].Affiliation.Affiliation | [ $id, .[0:rindex(" Electronic address:")] ] | #csv
Output:
"3233233233","Title content, Hematology and Hepatology Honorary Fellow, Honorary Member, American Society. xxxyyy#hotmail.com."
JqPlay Demo
Related
I have a column like
A. 'col' : [
'5ed3ede8844f0f351100000c',
'5ed3f117a844e0471100000d'
]
or some other case data
B. 'col' : [
'5ed3ede8844f0f351100000c'
]
C. 'col' : [
'5ed3ede8844f0f351100000c',
'5ed3f117a844e0471100000d',
'5ed3f18132f50c491100000e'
]
How to get A record that match exactly an array but regardless of the order of elements in the array with one query
Example
.find({'col': ['5ed3ede8844f0f351100000c','5ed3f117a844e0471100000d']})
or .find({'col': ['5ed3f117a844e0471100000d', '5ed3ede8844f0f351100000c']})
How to do that thanks
In order to find a record that match exactly a specified array without taking into consideration the order of the elements within the array, you can combine the $size and the $all query operators.
So for example:
.find({ 'col': { "$size": 2, "$all": ['5ed3f117a844e0471100000d', '5ed3ede8844f0f351100000c'] } })
Note: you can also use the $in query operator, but for your case it looks like the $all is a better fit
Use case: Remove a string from Azure Application Insights results
This is a simple question but with minimal examples online and as a new user, and with limited experience (but learning) in Regex, I am struggling.
How do I remove all instances of | Articles in the following table, which is an example of what I am exporting from Azure Application Insights?
This did not work:
| extend name=replace(#' | Articles', #'', name)
I have fiddled quite a bit unsuccessfully with an example in Microsoft's documentation (I know this interpretation is incorrect):
| extend str=strcat(' | Articles', tostring(name))
| extend replaced=replace(#' | Articles', #'', str)
Thank you for any insights.
the reason your initial attempt doesn't work is that the first argument to replace() is a regular expression, and if you have the pipe (|) in is, you'll need to properly escape it, using a backslash (\).
for example:
datatable(s:string)
[
"Article 1 | Articles",
"Article 2",
"Article 3 | Articles"
]
| extend replaced=replace(#' \| Articles', #'', s)
ideally, you'll choose a solution that doesn't require using a regular expression, if possible.
for example:
datatable(s:string)
[
"Article 1 | Articles",
"Article 2",
"Article 3 | Articles"
]
| extend i = indexof(s, " | Articles")
| project s = case(i == -1, s, substring(s, 0, i))
Given this JSON hash:
{
"id": 55555,
"name": "111111",
"custom_data_field": [
{
"id": 1,
"label": "Vehicle Type",
"value": "Coach"
},
{
"id": 2,
"label": "Vendor",
"value": 1
}
]
}
I need the value associated with each label.
I'm able to get the value using the array's index:
#item()?['custom_data_field'][0]['value'] # Coach
#item()?['custom_data_field'][1]['value'] # 1
But this is a bit fragile.
This syntax doesn't work:
#item()?['custom_data_field'][#label=='Vehicle Type']['value'] # Coach
#item()?['custom_data_field'][#label=='Vendor']['value'] # 1
Is there a way to do this reliably?
According to the description of your question, it seems the data {"id": 55555, "name": "111111"....} you provided is an item of a array list because your expression begins with item() (I guess you use this expression in a "For each" or something else loop action). And custom_data_field is array under the item, you want to do filter/select operation to get the value which its label equals Vehicle Type just by the expression. I don't think we can do it just in one expression (because the label and value are not key-value map, we can not do the filter/select in expression easily).
To meet the requirement, we need to use a more sophisticated approach such as "Filter array" action mentioned by Scott in comments. We need to set the array custom_data_field to the input box("From" box) of the "Filter array" action.
And then add the filter condition.
After running the logic app, it will filter the items by the filter condition.
As the filter action don't know how many items match the condition, so the output will always be a array but not an item or a record even if there is only one item matches the condition(label equals "Vehicle Type") in your custom_data_field list.
So if you want to get the value, you need to get it by writing an expression as below screenshot.
Hope it helps~
SuiteScript v1.
Searching on the item record type.
customrecord_sp_ecom_item_infoseo is a custom record type with a field called custrecord_sp_ecom_item_seo that references an item record. It also has a field called custrecord_sp_ecom_description, which is of type text.
I want to search for the items where the word "frozen" appears in custrecord_sp_ecom_description in the linked customrecord_sp_ecom_item_infoseo record and I want to use filter expressions.
Here's my expression:
[
[
"customrecord_sp_ecom_item_infoseo.custrecord_sp_ecom_description",
"contains",
"frozen"
]
]
And here's the error I get:
{"error" : {"code" : "SSS_INVALID_SRCH_FILTER_JOIN", "message" : "An nlobjSearchFilter contains an invalid join ID, or is not in proper syntax: custrecord_sp_ecom_description."}}
If I change the expression to:
[
[
"isonline",
"is",
true
]
]
then it works fine, albeit with the wrong results. So I know filter expressions can work, there's just something wrong with my expression.
How can I make it work?
When using the dot syntax for joins in filter expressions, the prefix of the dot is the ID of the field you are joining through, not the ID of the record type you are joining to (as it looks like you have here).
So, if I am searching Invoices, but I want to filter on the Sales Rep from the related Sales Order, it would look something like:
[
[ 'createdfrom.salesrep', 'anyof', salesReps]
]
Notice that it's not salesorder.salesrep, but rather createdfrom.salesrep because the createdfrom field is what links the record I am searching (Invoices) to the record I am joining (Sales Order). The same applies when using custom records. Your join will be something like custrecord_fieldid.custrecord_sp_ecom_description rather than using the record type.
I have a field that contains comma separated values which I want to perform suggestion on.
{
"description" : "Breakfast,Sandwich,Maker"
}
Is it possible to get only applicable token while performing suggest as you type??
For ex:
When I say break, how can I get only Breakfast and not get Breakfast,Sandwich,Maker?
I have tried using commatokenizer but it seems it does not help
As said in the documentation, you can provide multiple possible inputs by indexing like this:
curl -X PUT 'localhost:9200/music/song/1?refresh=true' -d '{
"description" : "Breakfast,Sandwich,Maker",
"suggest" : {
"input": [ "Breakfast", "Sandwitch", "Maker" ],
"output": "Breakfast,Sandwich,Maker"
}
}'
This way, you suggest with any word of the list as input.
Obtaining the corresponding word as suggestion from Elasticsearch is not possible but as a workaround you could use a tokenizer outside Elasticsearch to split the suggested string and choose only the one that has the input as prefix.
EDIT: a better solution would be to use an array instead of comma-separated values, but it doesn't meet your specs... ( look at this: Elasticsearch autocomplete search on array field )