I have solr field stored as -
record1 --> colorDimension : "Purple|91"
record2 --> colorDimension : "Purple|974|91"
record3 --> colorDimension : "Purple|974"
I need to facet on this colorDimension Field in a way such that term contains "Purple" and number "91".
The result I am targeting is -
Purple|91 = 2
I was looking out for facet.contains but did not get any examples that uses regular expressions.
You should expand these while indexing, so that you have a token for Purple|91 and Purple|974 separately. Faceting is quick because it can count tokens, without having to run a regex against each one to find the actual value.
You'll probably have to do this in your code, since I don't think you can make the pattern regex tokenizer spit out multiple tokens for a given prefix / group.
Try using this pattern:
Purple\|(?:\d+\|)*91(?:\||$)
Demo
If you actually need to make use of regular expressions, there is a parameter facet.matches, which can be used to specify a regular expression to restrict the facet results
Related
this my xpath
//dns:tbody//dns:td[1][#rowspan="1"]/text()
I want to find a solution how can make the attribute rowspan #rowspan=" only number " accept just number
I'm looking for solution regular expression in XPath 1.0
Regexp =^[0-9]*$
my problem I don't know how to integrate the regex with XPath1.0 or any other solution
You can use a workaround that tests:
if the text is a number (with the number() function)
if the text doesn't start with - (with starts-with())
if the text doesn't contain the dot (with contains())
like that:
//dns:tbody//dns:td[1][string(number(#rowspan))!='NaN'][not(starts-with(#rowspan, '-'))][not(contains(#rowspan, '.'))]/text()
or
//dns:tbody//dns:td[1][not(string(number(#rowspan))='NaN' or starts-with(#rowspan, '-') or contains(#rowspan, '.'))]/text()
Try to use below solution instead of regex:
//dns:tbody//dns:td[1][number(#rowspan)<=0 or number(#rowspan)>0]/text()
This should match #rowspan with int value
Some XPath implementations allow you to supply your own functions. You will need to check the documentation on your XPath implementation.
Java: http://xml.apache.org/xalan-j/xpath_apis.html#functionresolver
I use a jmeter for REST testing.
I have made a HTTP Request, and this is the response data:
{"id":11,"name":"value","password":null,"status":"ACTIVE","lastIp":"0.0.0.0","lastLogin":null,"addedDate":1429090984000}
I need just the ID (which is 11) in
{"id":11,....
I use the REGEX below :
([0-9].+?)
It works perfectly but it will be a problem if my ID more than 2 digits. I need to change the REGEX to :
([0-9][0-9].+?)
Is there any dynamic REGEX for my problem. Thank you for your attention.
Regards,
Stefio
If you want any integer between {"id": and , use the following Regular Expression:
{"id":(\d+),
However the smarter way of dealing with JSON data could be JSON Path Extractor (available via JMeter Plugins), going forward this option can be much easier to use against complex JSON.
See Using the XPath Extractor in JMeter guide (scroll down to "Parsing JSON") to learn more on syntax and use cases.
I suggest using the following regular expression:
"id":([^,]*),
This will first find "id": and then look for anything that is not a comma until it finds a comma. Note the character grouping is only around the value of the ID.
This will work for ANY length ID.
Edit:
The same concept works for almost any JSON data, for example where the value is quoted:
"key":"([^"]*)"
That regular expression will extract the value from given key, as long as value is quoted and does not contain quotes. It first finds "key": and then matches anything that is not a quote until the next quote.
You can use the quantifier like this:
([0-9]{2,}.+?)
It will catch 2 or more digits, and then any symbol, 1 or more times. If you want to allow no other characters after the digits, use * instead of +:
([0-9]{2,}.*?)
Regex demo
I would like to know how to query a field to exactly match a string.
I'm actually trying to query like this:
url : "http://www.domain_name.com"
Which returns all string starting with http://www.domain_name.com .
I had a similar issue, and ifound that ".raw" fixed it - in your example, try
url.raw : "http://www.domain_name.com"
Or for newer versions of ES(5.x, 6.x):
url.keyword : "http://www.domain_name.com"
Just giving more visibility to #dezhi's comment.
in newer version of ES(5.x, 6.x),
you should use `url.keyword` instead,
as they have changed to a new keyword type.
Therefore, it would be:
url.keyword : "http://www.domain_name.com"
Exact value is not supported out of the box.
http://blogs.perl.org/users/mark_leighton_fisher/2012/01/stupid-lucene-tricks-exact-match-starts-with-ends-with.html
Out of the box, Lucene does not provide exact field matches, like matching "Acer Negundo Ab" and only "Acer Negundo Ab" (not also "Acer
Negundo Ab IgG" ). Neither does Lucene provide "Starts With" or "Ends
With" functionality. Fortunately, there are workarounds.
"Cannot change the info of a user"
To search for an exact string, you need to wrap the string in double
quotation marks. Without quotation marks, the search in the example
would match any documents containing one of the following words:
"Cannot" OR "change" OR "the" OR "info" OR "a" OR "user".
Kibana v6.5
As per you query, it seems fine.
For matching the exact following is the syntax :
fieldname : string
and
For matchign the Substring, use wild card (*),
Syntax :
fieldname : *string*
Also, whatever the query you applied; is that query is the part of Query Criteria of your particuler output component.
So, i suggest you to check whether any of the wild card is applied in your search.
Given that I have a string such as
"Donald Trump <donald#trump.com>"
"Art Job <art#job.com>"
How can I find every row that contains "donald#trump.com" using MongoDB in Rails?
Thanks
From the documentation:
search_string = params['search']
# Constructor syntax coll.find({"name" => Regexp.new(search_string)})
# Literal syntax coll.find({"name" => /#{search_string}/})
Beware though... You can't use an index with this query since your regex isn't anchored to the front of the string.
You can perform such a search only using regular expressions:
http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-RegularExpressions
In your case you won't be able to search in a efficient way except you denormalize your data and store your email addresses in a dedicated attribute of the document.
No idea about Ruby but every driver should have support for regular expressions.
I have an input like this (a JSON format)
{"location":[{"id":"1BCDEFGHIJKLM","somename":"abcd","fewname":"xyzland","sid":"","sname":"","regionname":"Zee-Whole","type":"some","siteCode":"","someCode":"ROTXY","fewCode":"NL","pCode":"ROTXY","someid":"1BCDEFGHIJKLM","fewid":"GIC8"},{"id":"7823XYZHMOPRE","somename":"abcd Junction","fewname":"United States","sid":"","sname":"","regionname":"New York","type":"some","siteCode":"","someCode":"USRTJ","fewCode":"US","pCode":"USNWK","someid":"7823XYZHMOPRE","fewid":"7823XYZLMOPRE"},{"id":"799XYZHMOPRE","somename":"abcd-Maasvlakte","fewname":"xyzland","sid":"","sname":"","regionname":"Zee-Whole","type":"some","siteCode":"","someCode":"XYROT","fewCode":"NL","pCode":"","someid":"799XYZHMOPRE","fewid":"OIUOWER348534"}]}
Now, I want to pick up the first "id" value which is 1BCDEFGHIJKLM using regular expressions. I have managed upto the point using
[^({"location":[?{"id":")].{0,12} but this is incomplete. Could some one help how do I ignore the rest of the line after the value 1BCDEFGHIJKLM
Regex isn't the way to do this. Whatever platform you are using, it must have a JSON parser.
That will be your best error-free solution.
Assuming you must use regex, you can grab all the id's using "id":"(.*?)", and take the first match.
I found the following article, which might help you.
While messy, how is your regex incomplete?
It could be shortened to ("id":"([^"]+)") which is more readable, and doesn't limit the ID to twelve characters. If that is beneficial.
If you problem is getting more than one result, most languages have a "g" global switch.
In javascript, the following would return "1BCDEFGHIJKLM":
var firstID = str.match(/"id":"([^"]+)"/)[1]
As match()returns an array, in which [0] is the entire returned string, and [1] the first parenthasis.
Don't have to use regex. In your favourite language, split on commas. Then go through each item, check for "id" and split on colon (:). Get the last element. Eg Python
>>> s
'{"location":[{"id":"1BCDEFGHIJKLM","somename":"abcd","fewname":"xyzland","sid":"","sname":"","regionname":"Zee-Whole","type":"some","siteCode":"","someCode":"ROTXY","fewCode":"NL","pCode":"ROTXY","someid":"1BCDEFGHIJKLM","fewid":"GIC8"},{"id":"7823XYZHMOPRE","somename":"abcd Junction","fewname":"United States","sid":"","sname":"","regionname":"New York","type":"some","siteCode":"","someCode":"USRTJ","fewCode":"US","pCode":"USNWK","someid":"7823XYZHMOPRE","fewid":"7823XYZLMOPRE"},{"id":"799XYZHMOPRE","somename":"abcd-Maasvlakte","fewname":"xyzland","sid":"","sname":"","regionname":"Zee-Whole","type":"some","siteCode":"","someCode":"XYROT","fewCode":"NL","pCode":"","someid":"799XYZHMOPRE","fewid":"OIUOWER348534"}]}'
>>> for i in s.split(","):
... if '"id"' in i:
... print i.split(":")[-1]
... break
...
"1BCDEFGHIJKLM"
Of course, ideally, you should use a dedicated JSON parser.