4

I have data in my Elasticsearch with a field

PUT /logs/visited_domains/1
{
"visited_domain":"microsoft.com"
}
PUT /logs/visited_domains/2
{
"visited_domain":"not-microsoft.com"
}

The mapping is:

{
  "properties": {
    "visited_domain": {
      "type": "string",
      "index": "not_analyzed"
    }
  }
}

When I do an ElasticSearch of

{
  "query": {
    "filtered": {
      "filter": {
        "term": {
          "visited_domain": "microsoft.com"
        }
      }
    }
  }
}

I will get both results. But I only want the exact match. Any ideas of how I alter the query or improve the mapping?

EDIT: I changed one of my examples from notmicrosoft.com to not-microsoft.com because this dash is causing alot of the trouble. notmicrosoft.com does not return, but not-microsoft.com does, when searching for microsoft.com.

Saeed Zhiany
  • 2,051
  • 9
  • 30
  • 41
cybergoof
  • 1,407
  • 3
  • 16
  • 25

1 Answers1

4

Use query_string which gives exact match when used with quotes

 "query": {
     "query_string": {
          "default_field": "visited_domain",
                "query": "\"microsoft.com\""
                }
  }
Siddardha Budige
  • 1,005
  • 1
  • 8
  • 12
  • I managed to solve my exact problem using this method. I am unsure though on how to include the quotes if my query is a variable instead. – ChickenWing24 Jun 10 '15 at 02:59