0
votes

I have keyword analyzer as default analyzer, like so:

{
  "settings": {
    "index": {
      "analysis": {
        "analyzer": {
          "default": {
            "type": "keyword"
}}}}}}

```

But now I can't search anything. e.g:

{
  "query": {
    "query_string": {
      "query": "cast"
}}}

Gives me 0 results all though "cast" is a common value i the indexed documents. (http://gist.github.com/baelter/b0720a52ee5a27e27d3a)

Search for "*" works fine btw.

I only have explicit defaults in my mapping:

{
  "oceanography_point": {
    "_all" : {
      "enabled" : true
    },
    "properties" : {}
 }
}

The index behaves as if no fields are included in _all, because field:value queries works fine.

Am I misusing the keyword analyzer?

2

2 Answers

1
votes

Using keyword analyzer , you can only do an exact string match. Lets assume that you have used keyword analyzer and no filters. In that case for as string indexed as "Cast away in forest" , neither search for "cast" or "away" will work. You need to do an exact "Cast away in forest" string to match it. ( Assuming no lowercase filter used , you need to give the right case too)

A better approach would be to use multi fields to declare one copy as keyword analyzed and other one normal. You can search on one of this field and aggregate on the other.

1
votes

Okey, some 15h of trial and error I can conclude that this works for search:

{
  "settings": {
    "index": {
      "analysis": {
        "tokenizer": {
          "default": {
            "type": "keyword"
}}}}}}

How ever this breaks faceting so I ended up using a dynamic template instead:

"dynamic_templates" : [
  {
    "strings_not_analyzed" : {
      "match" : "*",
      "match_mapping_type" : "string",
      "mapping" : {
        "type" : "string",
        "index" : "not_analyzed"
      }
    }
  }
],