How can I escape "." characters in Artillery to prevent nesting? - artillery

I have an artillery file where one of my requests is defined as so:
{
"post": {
"url": "/apps/stash/foo/search",
"json": {
"size": 100,
"from": 0,
"query": {
"bool": {
"must": {
"nested": {
"path": "text_analytics.entities.person",
"query": {
"bool": {
"must": {
"match": {
"text_analytics.entities.person.text": "Boris Johnson"
}
}
}
}
}
}
}
}
}
}
}
However, when I run this request, the json that gets sent out is this:
{
"json": {
"size": 100,
"from": 0,
"query": {
"bool": {
"must": {
"nested": {
"path": "text_analytics.entities.person",
"query": {
"bool": {
"must": {
"match": {
"text_analytics.entities.person.text": "Boris Johnson",
"text_analytics": {
"entities": {
"person": {
"text": "Boris Johnson"
}
}
}
}
}
}
}
}
}
}
}
}
}
As you can see, it has added a key to the match object called text_analytics where it has automatically nested objects by splitting on the . character.
How can I stop artillery doing this?

Looks like it's actually a bug in artillery.
https://github.com/artilleryio/artillery/issues/723

Related

Elasticsearch query in array conditions on doc fields

I have a document like this:
{
"_index": "listings",
"_type": "listing",
"_id": "234",
"_source": {
"category_id": "43608",
"categories": [
43608,
43596
]
}
}
I wanna query to array search category_id in categories. some thing like that
{
"query": {
"bool": {
"must": [
{
"terms": {
"category_id": "doc.categories"
}
}
]
}
}
}
What I supposed to do?
As, category_id is a string type, better to use SHOULD query instead of MUST and Simply, Itrate through the array categories and make separate term level query for each element in array.
{
"query": {
"bool": {
"should": [
{
"term": {
"category_id": "doc.categories[0]"
}
},
{
"term": {
"category_id": "doc.categories[1]"
}
},
...
]
}
}
}
It will return you all which match any of categories array.
You have to user script for find a field value in another field value.
{
"script": {
"script": {
"source": "doc.containsKey('categories') && doc['categories'].values.contains(doc['category_id'].value)",
"lang": "painless"
}
}
}

Elasticsearch query identical arrays

I have documents like these:
Doc1
{
"id": ...,
...
"articles": [
{
"id": "5cdd17c7e24f6e05d487b2c2#142936",
...
},
{
"id": "5cdd17c7e24f6e05d487b2c2#226536",
...
}
...
}
Doc2
{
"id": ...,
...
"articles": [
{
"id": "5cdd17c7e24f6e05d487b2c2#142936",
...
},
{
"id": "5cdd17c7e24f6e05d487b2c2#226536",
...
},
{
"id": "5cdd17c7e24f6e05d487b2c2#142965",
...
}
...
}
Doc3
{
"id": ...,
...
"articles": [
{
"id": "5cdd17c7e24f6e05d487b2c2#142936",
...
}
...
}
And I want the document exactly has the array of articles I need. For example, if my Array of article Ids is ['5cdd17c7e24f6e05d487b2c2#142936', '5cdd17c7e24f6e05d487b2c2#226536'] I only want to get the Doc1.
Now I have this query:
GET my_index/_search
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "articles",
"query": {
"query_string": {
"default_field": "articles.id",
"query": "5cdd17c7e24f6e05d487b2c2#142936 AND 5cdd17c7e24f6e05d487b2c2#226536"
}
}
}
}
]
}
}
}
But with this, I get Doc1 & Doc2...
Assuming articles.id is of type keyword, I think this should work for you (not sure it's the most efficient way to write the query):
GET my_index/_search
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "articles",
"query": {
"term": {
"articles.id": "5cdd17c7e24f6e05d487b2c2#142936"
}
}
}
},
{
"nested": {
"path": "articles",
"query": {
"term": {
"articles.id": "5cdd17c7e24f6e05d487b2c2#226536"
}
}
}
}
],
"must_not": {
"nested": {
"path": "articles",
"query": {
"query_string": {
"default_field": "articles.id",
"query": "NOT 5cdd17c7e24f6e05d487b2c2#142936 AND NOT 5cdd17c7e24f6e05d487b2c2#226536"
}
}
}
}
}
}
}

JOLT filter array elements based on existence of a key field

Is it possible to filter array elements based on presence of a field.
My input JSON is as below:
{
"payload": {
"logical": {
"schemas": [
{
"name": "myschema",
"tables": [
{
"name": "myname",
"alias": "temp_alias",
"keys": [
{
"name": "value1",
"key": "key1",
"match": "match_val"
},
{
"name": "value1",
"key": "key2",
"match": "match_val"
},
{
"name": "value1",
"key": "key3"
},
{
"name": "value1",
"key": "key4"
}
]
}
]
}
]
}
}
}
Expected output is:
{
"payload": {
"logical": {
"schemas": [
{
"tables": [
{
"name": "myname",
"alias": "temp_alias",
"keys": {
"name": "value1",
"match": "match_val",
"key": [
"key1",
"key2"
]
}
}
]
}
]
}
}
}
If there is "match" field in "keys" element, then we will take "key" value from that element and put in the output array "key".
I am using this spec file, but not getting required output. Can anyone please suggest how to do it?
[
{
"operation": "shift",
"spec": {
"*": "&",
"payload": {
"*": "&",
"logical": {
"schemas": {
"*": {
"tables": {
"*": {
"name": "payload.logical.schemas[&3].tables[&1].name",
"alias": "payload.logical.schemas[&3].tables[&1].alias",
"keys": {
"*": {
"match": {
"match1|match2": {
"#2": {
"name": "payload.logical.schemas[&4].tables[&4].keys.name",
"match": "payload.logical.schemas[&4].tables[&4].keys.match",
"key": "payload.logical.schemas[&4].tables[&4].keys.key"
}
}
}
}
}
}
}
}
}
}
}
}
}
]
I got desired output with below spec file:
[
{
"operation": "shift",
"spec": {
"*": "&",
"payload": {
"*": "&",
"logical": {
"schemas": {
"*": {
"tables": {
"*": {
"name": "payload.logical.schemas[&3].tables[&1].name",
"alias": "payload.logical.schemas[&3].tables[&1].alias",
"keys": {
"*": {
"match": {
"*": {
"#(2,name)": "payload.logical.schemas[&7].tables[&5].keys[&3].name",
"#(2,match)": "payload.logical.schemas[&7].tables[&5].keys[&3].match",
"#(2,key)": "payload.logical.schemas[&7].tables[&5].keys[&3].key"
}
}
}
}
}
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": "&",
"payload": {
"*": "&",
"logical": {
"schemas": {
"*": {
"tables": {
"*": {
"name": "payload.logical.schemas[&3].tables[&1].name",
"alias": "payload.logical.schemas[&3].tables[&1].alias",
"keys": {
"*": {
"name": "payload.logical.schemas[&5].tables[&3].keys.name",
"match": "payload.logical.schemas[&5].tables[&3].keys.match",
"key": "payload.logical.schemas[&5].tables[&3].keys.key"
}
}
}
}
}
}
}
}
}
},
{
"operation": "cardinality",
"spec": {
"payload": {
"logical": {
"schemas": {
"*": {
"tables": {
"*": {
"keys": {
"name": "ONE",
"match": "ONE"
}
}
}
}
}
}
}
}
}
]

Cloudant: Check if array is empty

I've this entry:
"entries": {
"members": {
"person": [
{
"name": "Jane Doe",
}
]}}
Now I would like to check if the persons array is empty or has some entries.
I already tried with $exists:
"selector": {
"entries": {
"members": {
"person": {
"name": {
"$exists": true
}
}
}
}
}
}
And with $neq
"selector": {
"entries": {
"members": {
"person": {
"name": {
"$neq": ""
}
}
}
}
}
}
Both approaches don't work..any tips?
you may want try using the $size operator. for example,
"selector": {
"entries": {
"members": {
"person": {
"$size": 0
}
}
}
}
I did it with:
"entries.members.person": {
"$elemMatch": {
"name": {
"$exists": true
}
}
}

ElasticSearch-Kibana : filter array by key

I have data with one parameter which is an array. I know that objects in array are not well supported in Kibana, however I would like to know if there is a way to filter that array with only one value for the key. I mean :
This is a json for exemple :
{
"_index": "index",
"_type": "data",
"_id": "8",
"_version": 2,
"_score": 1,
"_source": {
"envelope": {
"version": "0.0.1",
"submitter": "VF12RBU1D53087510",
"MetaData": {
"SpecificMetaData": [
{
"key": "key1",
"value": "94"
},
{
"key": "key2",
"value": "0"
}
]
}
}
}
}
And I would like to only have the data which contains key1 in my SpecificMetaData array in order to plot them. For now, when I plot SpecificMetaData.value it takes all the values of the array (value of key1 and key2) and doesn't propose SpecificMetaData.value1 and SpecificMetaData.value2.
If you need more information, tell me. Thank you.
you may need to map your data to mappings so as SpecificMetaData should act as nested_type and inner_hits of nested filter can supply you with objects which have key1.
PUT envelope_index
{
"mappings": {
"document_type": {
"properties": {
"envelope": {
"type": "object",
"properties": {
"version": {
"type": "text"
},
"submitter": {
"type": "text"
},
"MetaData": {
"type": "object",
"properties": {
"SpecificMetaData": {
"type": "nested"
}
}
}
}
}
}
}
}
}
POST envelope_index/document_type
{
"envelope": {
"version": "0.0.1",
"submitter": "VF12RBU1D53087510",
"MetaData": {
"SpecificMetaData": [{
"key": "key1",
"value": "94"
},
{
"key": "key2",
"value": "0"
}
]
}
}
}
POST envelope_index/_search
{
"query": {
"bool": {
"must": [
{
"nested": {
"inner_hits": {},
"path": "envelope.MetaData.SpecificMetaData",
"query": {
"bool": {
"must": [
{
"term": {
"envelope.MetaData.SpecificMetaData.key": {
"value": "key1"
}
}
}
]
}
}
}
}
]
}
}
}

Resources