当前位置: 动力学知识库 > 问答 > 编程问答 >

search - Elasticsearch Failed to find analyzer but it creates index without any error

问题描述:

Here is my index settings json, when I test

http://localhost:9200/myIndex/_analyze?text="testing the analyzer"&analyzer=nGram_analyzer

I am getting the following exception.

{

"error": {

"root_cause": [

{

"type": "remote_transport_exception",

"reason": "[Infectia][127.0.0.1:9300][indices:admin/analyze[s]]"

}

],

"type": "illegal_argument_exception",

"reason": "failed to find analyzer [nGram_analyzer]"

},

"status": 400

}

index settings

 {

"myIndex": {

"mappings": {

"practices": {

"properties": {

"practiceCity": {

"type": "string",

"index":"analyzed",

"analyzer": "nGram_analyzer"

},

"practiceId": {

"type": "long",

"index":"not_analyzed"

},

"practiceName": {

"type": "string",

"boost": 10,

"index":"analyzed",

"analyzer": "nGram_analyzer"

},

"practicePhone": {

"type": "long",

"boost": 10,

"index":"analyzed",

"analyzer": "nGram_analyzer"

},

"practiceService": {

"type": "string",

"boost": 5,

"index":"not_analyzed"

}

}

},

"users": {

"_all": {

"analyzer": "nGram_analyzer"

},

"properties": {

"userCityId": {

"type": "long",

"index":"not_analyzed",

"analyzer": "nGram_analyzer"

},

"userCityName": {

"type": "string",

"index":"not_analyzed"

},

"userEmail": {

"type": "string",

"index":"analyzed",

"analyzer": "nGram_analyzer"

},

"userFirstName": {

"type": "string",

"boost": 10,

"index":"analyzed",

"analyzer": "nGram_analyzer"

},

"userId": {

"type": "long"

},

"userLastName": {

"type": "string",

"boost": 10,

"index":"analyzed",

"analyzer": "nGram_analyzer"

},

"userMobile": {

"type": "string",

"index":"analyzed",

"analyzer": "nGram_analyzer"

},

"userSpecialization": {

"type": "string",

"boost": 5,

"index":"not_analyzed"

}

}

}

},

"settings": {

"index": {

"analysis": {

"analyzer": {

"nGram_analyzer": {

"type": "custom",

"tokenizer": "standard",

"filter": [

"nGram_filter"

]

}

},

"filter": {

"nGram_filter": {

"max_gram": "20",

"type": "edgeNGram",

"min_gram": "3",

"token_chars": [

"letter",

"digit",

"punctuation",

"symbol"

]

}

}

},

"number_of_replicas": "1",

"number_of_shards": "5"

}

}

}

}

I am working on the auto complete functionality, is my index looks good?

is there any suggestions for performance improvement?

网友答案:

You need to change the settings section like this: (i.e. analysis goes directly under settings not in index)

PUT myindex
{
  "mappings": {
    "practices": {
      "properties": {
        "practiceCity": {
          "type": "string",
          "index": "analyzed",
          "analyzer": "nGram_analyzer"
        },
        "practiceId": {
          "type": "long",
          "index": "not_analyzed"
        },
        "practiceName": {
          "type": "string",
          "boost": 10,
          "index": "analyzed",
          "analyzer": "nGram_analyzer"
        },
        "practicePhone": {
          "type": "long",
          "boost": 10
        },
        "practiceService": {
          "type": "string",
          "boost": 5,
          "index": "not_analyzed"
        }
      }
    },
    "users": {
      "properties": {
        "userCityId": {
          "type": "long"
        },
        "userCityName": {
          "type": "string",
          "index": "not_analyzed"
        },
        "userEmail": {
          "type": "string",
          "index": "analyzed",
          "analyzer": "nGram_analyzer"
        },
        "userFirstName": {
          "type": "string",
          "boost": 10,
          "index": "analyzed",
          "analyzer": "nGram_analyzer"
        },
        "userId": {
          "type": "long"
        },
        "userLastName": {
          "type": "string",
          "boost": 10,
          "index": "analyzed",
          "analyzer": "nGram_analyzer"
        },
        "userMobile": {
          "type": "string",
          "index": "analyzed",
          "analyzer": "nGram_analyzer"
        },
        "userSpecialization": {
          "type": "string",
          "boost": 5,
          "index": "not_analyzed"
        }
      }
    }
  },
  "settings": {
    "index": {
      "number_of_replicas": "1",
      "number_of_shards": "5"
    },
    "analysis": {
      "analyzer": {
        "nGram_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "nGram_filter"
          ]
        }
      },
      "filter": {
        "nGram_filter": {
          "max_gram": "20",
          "type": "edgeNGram",
          "min_gram": "3",
          "token_chars": [
            "letter",
            "digit",
            "punctuation",
            "symbol"
          ]
        }
      }
    }
  }
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: