Using Xpath Not - xpath

I have the following that I am generating in an Xpath query:
<xforms:instance id="Instance">
{//xforms:instance[#id="Instance"][ .= "Code" ]}
<Code>blah</Code>
</xforms:instance>
As it is it will return where the tag is 'Code' in the instance block. However, I want it to return everything else, and not 'Code'
I have tried variations including:
[ .not(="Code") ]}
[ .!= "Code" ]}
But these don't seem to work. I'd be grateful for your help.
Thanks.

Do you just want the text node?
/xforms:instance/text()

Related

Laravel Binary String Issue When DB:raw and Pluck() or toArray()

So when i use retrieve an object using get, i got a normal result
Code:
Contact::select(\DB::raw("CONCAT(COALESCE(`name`,''),' ',COALESCE(`last_name`,'')) AS display_name"),'id','name','last_name')->where('id',2382)->get()
Result:
[
"display_name" => "OFNA • CASA "
"id" => 2382
"name" => "OFNA • CASA"
"last_name" => null
]
but if i do a ->pluck() or ->toArray() i got this result:
[
"display_name" => b"Ofna €¢ Casa "
"id" => 2382
"name" => "OFNA • CASA"
"last_name" => null
]
For some reason the display_name is encoding incorrectly when converting to an Array. is there a way to fix this? or is a Laravel issue?
Thanks
My Laravel version is 6.8
I made a workaround, but im sure there should be a fix to this issue
This is my work around, map the get and then use the pluck on the collection after the map
get()->
map(function($object){
return [
'name'=>$object->name.' '.$object->last_name,
'id'=>$object->id
];
})->pluck('name','id');
It does work but im sure there should be a better way or maybe report it to Laravel.
Hope someone knows better about this.
THanks

Nesting existing collection inside object

I'm trying to configure filter mutates properly for a logastash configuration file, but I fail.
I have a tags array which comes from SQL as a string like this:
"lunch | mellanmål | middag"
I configure mutate to split it into collection like this:
mutate { split => ["meal_type_tags", " | "] }
I'm getting an index with an expected collection:
"meal_type_tags" : ["lunch", "mellanmål","middag"]
I'm trying rename to nest it inside a new tags object by adding another mutate:
mutate { rename => "meal_type_tags" => "[tags][meal_type]"}
My expected index is:
"tags": {
"meal_type" :
[
"lunch",
"mellanmål"
"middag"
]
}
...but I get this instead:
"tags" : [
[
"meal_type",
[
"middag",
"lunch"
]
]
]
I don't know why but it just wouldn't work if I tried rename to tags. I changed to recipe_tags and it worked I expected. Maybe #baudsp know more, as the solution was inspired by his comment.

Fos Elastica remove common words(or, and etc..) from search query

Hello I`m trying to get query results using FosElasticaBundle with this query, I
can't find a working example for filtering common words like (and, or) if it is possible this words not to be highlighted also would be really good. My struggle so far :
$searchForm = $this->createForm(SearchFormType::class, null);
$searchForm->handleRequest($request);
$matchQuery = new \Elastica\Query\Match();
$matchQuery->setField('_all', $queryString);
$searchQuery = new \Elastica\Query();
$searchQuery->setQuery($matchQuery);
$searchQuery->setHighlight(array(
"fields" => array(
"title" => new \stdClass(),
"content" => new \stdClass()
),
'pre_tags' => [
'<strong>'
],
'post_tags' => [
'</strong>'
],
'number_of_fragments' => [
'0'
]
));
Thanks in advance ;)
Do you want (and, or) to be ignored or not to have a value on your search?
If that's the case you may want to use stop words on your elasticsearch index.
Here's a reference.
https://www.elastic.co/guide/en/elasticsearch/guide/current/using-stopwords.html

Elasticsearch - how to append term?

Is there a way to append term into an array of values?
For example if my document looks like this:
{
"items": ["item1", "item2", "item3"]
}
I want to append "item4" and "item5" to it.
I must do it in 2 queries? one to load the current list of values, and on to update that list? or is there more elegant way that will let me append those items in one query?
I am trying to do it with elastic4s like this:
client.execute(ElasticDsl.update id id in indexName / documentType script {
script(s"ctx._source.items += tag").params(Map("tag"->"item4"))
})
In order to use the above code snippet, I need to enable groovy scripts, and I am not sure how to do it with multiple items.
Any idea?
Here is a full example of how you could achieve this.
Merge new values to array and make it unique after:
DELETE test/test/1
POST test/test/1
{
"terms":["item1", "item2", "item3"]
}
GET test/test/1
POST test/test/1/_update
{
"script" : " ctx._source.terms << newItems; ctx._source.terms = ctx._source.terms.flatten().unique()",
"params" : {
"newItems" : ["a","b"]
}
}
make sure you have scripting enabled in server config
user:/etc/elasticsearch# head elasticsearch.yml
script.inline: true
script.indexed: true
...
Try using 'terms' filter in your code.If you are using NEST then following link will be useful https://nest.azurewebsites.net/nest/writing-queries.html

Parsing XML document with namespace using logstash

I am trying to parse the following xml data using logstash.I am able to do it by removing the namespace from tags.But when I am trying it on the actual documents which is having namespace in it, its not able to parse the fields. Can someone help with the use of namespace or whether I am going wrong somewhere else?
<Book:Body>
<Book:Head>
<bookname>Book:Name</bookname>
<ns:Hello xmlns:ns="www.example.com">
<ns:BookDetails>
<ns:ID>123456</ns:ID>
<ns:Name>ABC</ns:Name>
</ns:BookDetails>
</ns:Hello xmlns:ns="www.example.com">
</Book:Head>
</Book:Body>
Following is my config file:
multiline {
pattern => "<Book:Body>"
what => "previous"
negate => "true"
}
xml {
store_xml => "false"
source => "message"
remove_namespaces => "true"
xpath =>[
"/Book/Book/BookDetails/ID/text()","ID",
"/Book/Book/BookDetails/Name/text()","Name"
]
}
mutate {
add_field => ["IDIndexed", "%{ID}"]
add_field => ["NameIndexed", "%{Name}"]
}
As it is not getting parsed, I am just getting %{ID} and %{Name} using mutate instead of getting their actual values.
Problem is in xpath :
try this
xpath => [
"/Body/head/Hello/BookD/BookDetails/ID/text()", "ID",
"/Body/head/Hello/BookD/BookDetails/Name/text()", "Name",
]

Resources