请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

3-11的自定义分词不生效

跟着视频敲的, 不生效

PUT test_index_2
{
	"settings": {
		"analysis": {
			"analyzer": {
				"my_custom_analyzer": {
					"type": "custom",
					"char_filter": [
						"emoticons"
					],
					"tokenizer": "punctuation",
					"filter": [
						"lowercase",
						"english_stop"
					]
				}
			},
			"tokenizer": {
				"punctuation": {
					"type": "pattern",
					"pattern": "[.,?!]"
				}
			},
			"char_filter": {
				"emoticons": {
					"type": "mapping",
					"mappings": [
						":)=>happy",
						":(=>cry"
					]
        }
			},
			"filter": {
				"english_stop": {
					"type": "stop",
					"stopwords": "_english_"
				}
			}
		}
	}
}

正在回答 回答被采纳积分+3

2回答

rockybean 2021-02-28 07:58:41

这个是因为你 :) 配置和测试不一致,前者英文,后者中文,参见下面

GET test_index_2/_analyze

{

  "analyzer": "my_custom_analyzer",

  "text": "hi, he drink milk! :)"

}




PUT test_index_2

{

"settings": {

"analysis": {

"analyzer": {

"my_custom_analyzer": {

"type": "custom",

"char_filter": [

"emoticons"

],

"tokenizer": "punctuation",

"filter": [

"lowercase",

"english_stop"

]

}

},

"tokenizer": {

"punctuation": {

"type": "pattern",

"pattern": "[.,?!]"

}

},

"char_filter": {

"emoticons": {

"type": "mapping",

"mappings": [

":)=>happy",

":(=>cry"

]

        }

},

"filter": {

"english_stop": {

"type": "stop",

"stopwords": "_english_"

}

}

}

}

}


0 回复 有任何疑惑可以回复我~
rockybean 2021-02-27 18:19:45

es 的版本是多少?

报错是什么?

0 回复 有任何疑惑可以回复我~
  • 提问者 rick_and_ #1
    版本7.X 没有报错,但是分词没生效.
    POST test_index_1/_analyze
    {
    	"analyzer": "my_analyzer",
    	"text": "hi, he drink milk! :)"
    }
    分词的结果是这样
    {
      "tokens" : [
        {
          "token" : "hi",
          "start_offset" : 0,
          "end_offset" : 2,
          "type" : "word",
          "position" : 0
        },
        {
          "token" : " he drink milk",
          "start_offset" : 3,
          "end_offset" : 17,
          "type" : "word",
          "position" : 1
        },
        {
          "token" : " :)",
          "start_offset" : 18,
          "end_offset" : 21,
          "type" : "word",
          "position" : 2
        }
      ]
    }
    回复 有任何疑惑可以回复我~ 2021-02-27 23:28:49
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信