0

First of all I'm completly new to ES. I created ES search criteria below for searching items which works fine but what I now need is, I want to turn make field into case-insensitive so that the search result would be the same for hello, HeLlo, HELLO so on.

I've read post below couldn't quiet apply to my example below because of my very limited knowledge:

Removing not_analyzed from make doesn't help.

'indexes' => [
    'my_project' => [
        'client' => 'default',
        'index_name' => 'hello',
        'settings' => [
            'index' => [
                'analysis' => [
                    'analyzer' => [
                        'snowball_analyzer' => [
                            'type' => 'snowball',
                            'language' => 'English',
                        ],
                    ],
                ],
            ],
        ],
        'types' => [
            'item' => [
                'mappings' => [
                    'uuid' => ['type' => 'string', 'index' => 'not_analyzed'],
                    'name' => ['type' => 'string', 'boost' => 8, 'analyzer' => 'snowball_analyzer'],
                    'make' => ['type' => 'string', 'index' => 'not_analyzed'],
                ]
            ],
        ],
    ],
],

These is the query that I created:

1

{
  "query": {
    "filtered": {
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "make": "HeLlo"
              }
            }
          ]
        }
      }
    }
  }
}
Community
  • 1
  • 1
BentCoder
  • 12,257
  • 22
  • 93
  • 165
  • There is no search criteria in the post. Searching for case insensitive is both about mapping and/or the search itself. – Andrei Stefan Jul 22 '15 at 11:16

2 Answers2

0

You have to add the "lowercase" filter. Here is an extract for a similar configuration I use:

settings:
    index:
        analysis:
            analyzer:
                custom_search_analyzer:
                    type: custom
                    tokenizer: standard
                    filter: [stopwords, asciifolding ,lowercase, snowball, elision, worddelimiter]

In your case, I guess you should change like this:

...                    
'settings' => [
    'index' => [
        'analysis' => [
            'analyzer' => [
                'snowball_analyzer' => [
                    'type' => 'snowball',
                    'language' => 'English',
                    'filter' => [ 'lowercase' ]
                ],
            ],
        ],
    ],
],                        
...
Francesco Abeni
  • 4,190
  • 1
  • 19
  • 30
  • I just added `'filter' => [ 'lowercase' ]` bit but no luck. – BentCoder Jul 22 '15 at 10:37
  • I just read that lowercase filter should be enabled by default in snowball, see https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-snowball-analyzer.html . So unfortunately my answer does not apply. Sorry for misleading you. – Francesco Abeni Jul 22 '15 at 11:56
  • No problem at all. That happens. Thank you for the effort anyway. – BentCoder Jul 22 '15 at 20:28
0

I went thru the answer in the first link I posted with my eyes open this time and it solved my problem too so my case-insensitive working example is:

{
  "query": {
    "filtered": {
      "query": {
        "bool": {
          "must": [
            {
               "query_string": {
                  "query": "HeLlo*"
                }
            }
          ]
        }
      }
    }
  }
}
BentCoder
  • 12,257
  • 22
  • 93
  • 165