问题描述
在这段代码中,我为索引时间和搜索时间定义了两个不同的自定义分析器,并且在映射字段中,我还指定了“分析器”和“ search_analyzer”。
PUT /demo
{
"settings": {
"index": {
"analysis": {
"filter": {
"synonym_test":{
"type":"synonym","synonyms_path":"analysis/output.txt"
},"english_stop":{
"type":"stop","stopwords":"_english_"
},"en_US":{
"type":"hunspell","language":"en_US"
}
},"analyzer": {
"autocomplete": {
"filter": [
"lowercase","synonym_test","english_stop","en_US"
],"type":"custom","tokenizer": "standard"
},"complete":{
"filter": [
"lowercase","tokenizer": "standard"
}
}
}
}
},"mappings": {
"properties": {
"Content":{
"type": "text","analyzer": "autocomplete","search_analyzer": "complete"
},"query":{
"type":"percolator"
}
}
}
}
我使用分析api检查了上述查询。
GET demo/_analyze
{
"text": "fractured","analyzer": "autocomplete"
}
它显示令牌:
{
"tokens" : [
{
"token" : "fracture","start_offset" : 0,"end_offset" : 9,"type" : "<ALPHANUM>","position" : 0
}
]
}
也在运行中:
GET demo/_analyze
{
"text": "fractured","analyzer": "complete"
}
它显示令牌:
{
"tokens" : [
{
"token" : "fracture","position" : 0
}
]
}
我有一个演示:
PUT demo/_doc/1
{
"Content":"fracture foot"
}
但是当我将搜索查询写为:
GET demo/_search
{
"query": {
"match": {
"Content": {
"query": "fracture"
}
}
}
}
或者如果我写:
GET demo/_search
{
"query": {
"match": {
"Content": {
"query": "fractured"
}
}
}
}
对于这两个查询,我都得到空结果。 请帮助我解决这个问题。 en_US是Hunspell词典的词干,我还添加了同义词过滤器。 请帮助我。
解决方法
问题已解决,我只是将同义词文件中的同义词从“ fracture => break,split,rupture,broken”更改为“ fracture,break,split,破裂,breaking”,现在所有词都已被编入索引