Search code examples
azure-cognitive-search

Azure Search Custom Analyzer


We are trying to use a custom analyzer (KeywordAnalyzer) using Azure Search Rest api-version: 2015-02-28-preview.

The Index definition code you see below is copied exactly from Microsoft docs. This works if we put the Analyzer Type to CustomAnalyzer. However, if we make a single change by changing the analyzer type from CustomAnalyzer to any other analyzer such as KeywordAnalyzer, you get a Bad Request error when creating the Index and the Index is not created.

Would appreciate if anyone coud tell us how we can specify an Analyzer.

Many thanks

 {
           "name":"homes",
           "fields":[
              {
                 "name":"Id",
                 "type":"Edm.String",
                 "key":true,
                 "searchable":false},
              {
                 "name":"IdStd",
                 "type":"Edm.String",
                 "searchable":true,
                 "analyzer":"my_analyzer"}
           ],
           "analyzers":[
              {
                 "name":"my_analyzer",
                 "@odata.type":"#Microsoft.Azure.Search.CustomAnalyzer",
                 "tokenizer":"my_standard_tokenizer",
                 "tokenFilters":[
                    "my_asciifolding",
                    "lowercase"
                 ]
              }
           ],
           "tokenizers":[
              {
                 "name":"my_standard_tokenizer",
                 "@odata.type":"#Microsoft.Azure.Search.StandardTokenizer",
                 "maxTokenLength":20}
           ],
           "tokenFilters":[
              {
                 "name":"my_asciifolding",
                 "@odata.type":"#Microsoft.Azure.Search.AsciiFoldingTokenFilter",
                 "preserveOriginal":true}
           ]
    }

Solution

  • I'm from Azure Search. What's the error message you're seeing together with the BadRequest response code?

    Edit: I reread you question. Potentially you are specifying the tokenizer and tokenFilter properties for the KeywordAnalyzer. These properties only apply to the CustomAnalyzer. Please let me know if you find the documentation insufficient or confusing. We'll make sure to make it more clear and easier to follow.