0
votes

I want to set a global analyzer for any index in Elasticsearch.

These lines are added into elasticsearch.yaml:

index.analysis.analyzer.ik.type: ik
index.analysis.analyzer.default.type: ik
index.analysis.analyzer.standard.type: ik

After restarting Elasticsearch, these lines are shown in http://localhost:9200/_nodes/settings

index: {
  analysis: {
    analyzer: {
      standard: {
        type: "ik"
      },
      default: {
        type: "ik"
      },
      ik: {
        type: "ik"
      }
    }
  }
}

Then I tested with url http://localhost:9200/_analyze?text=时间&analyzer=ik

{
  tokens: [
    {
       token: "时间",
       start_offset: 0,
       end_offset: 2,
       type: "CN_WORD",
       position: 0
    }
  ]
}

It shows the IKAnalyzer is enabled. However, when it comes to http://localhost:9200/_analyze?text=时间&analyzer=standard or http://localhost:9200/_analyze?text=时间, the "standard" analyzer results are returned:

{
  tokens: [
    {
       token: "时",
       start_offset: 0,
       end_offset: 1,
       type: "<IDEOGRAPHIC>",
       position: 0
    },
    {
       token: "间",
       start_offset: 1,
       end_offset: 2,
       type: "<IDEOGRAPHIC>",
       position: 1
    }
  ]
}

So, what should I do?

1

1 Answers

1
votes

Default analyzer settings affects real indexed documents, not "test" requests you do with http://localhost:9200/_analyze. Try to add few docs to an index and then see if the search works as you expect