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.

4

1 回答 1

4

使用 query_string 与引号一起使用时给出完全匹配

 "query": {
     "query_string": {
          "default_field": "visited_domain",
                "query": "\"microsoft.com\""
                }
  }
于 2014-08-27T18:24:31.320 回答