58

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 .

smace
  • 1,088
  • 2
  • 11
  • 16

5 Answers5

67

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"
victorkt
  • 13,992
  • 9
  • 52
  • 51
MarkD
  • 1,025
  • 8
  • 12
  • 2
    Thanks a lot, with .raw we can access to the unfiltered/untokenized string! – smace Nov 17 '14 at 22:26
  • 24
    in newer version of ES(5.x, 6.x), you should use url.keyword instead, as they have changed to a new keyword type. – dezhi Jun 08 '17 at 13:06
50

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"
Nathan McCoy
  • 3,092
  • 1
  • 24
  • 46
6

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.

JAR.JAR.beans
  • 9,668
  • 4
  • 45
  • 57
2
"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

Max
  • 4,292
  • 1
  • 20
  • 14
  • Your answer is very much correct except 1 small thing. "Cannot change the info of a user" would even fetch a document where text would be something like: "Unautorized User Cannot change the info of a user" so anything inside "" is matched as complete phrase. I guess for exact match above answers for url.raw or url.keyword are more correct. – GPuri Nov 16 '21 at 15:48
-8

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.

Nirdesh Sharma
  • 734
  • 5
  • 14
  • Thanks for your answer Nirdesh, but unfortunately there are some irregularities here with the actual functionality. – robert Dec 15 '17 at 23:39