雪球干扰器无法正常工作

时间:2016-06-17 16:37:49

标签: elasticsearch nest stemming snowball snowballanalyzer

我使用elasticsearch2.3.3和Nest 2.3.2为附件创建了一个索引。下面给出了索引。我在文档中搜索复数形式的单数词。阅读雪球词干将进行这种类型的转换。但是没有在搜索上返回任何记录。是否需要在应用程序中添加任何额外的插件/单词集合以使其工作。谁能帮忙。

 {  
 "mydocs":{  
   "aliases":{  

  },
  "mappings":{  
     "indexdocument":{  
        "properties":{  
           "docLocation":{  
              "type":"string",
              "index":"not_analyzed",
              "store":true
           },
           "documentType":{  
              "type":"string",
              "store":true
           },
           "file":{  
              "type":"attachment",
              "fields":{  
                 "content":{  
                    "type":"string"
                 },
                 "author":{  
                    "type":"string"
                 },
                 "title":{  
                    "type":"string",
                    "term_vector":"with_positions_offsets",
                    "analyzer":"full"
                 },
                 "name":{  
                    "type":"string"
                 },
                 "date":{  
                    "type":"date",
                    "format":"strict_date_optional_time||epoch_millis"
                 },
                 "keywords":{  
                    "type":"string"
                 },
                 "content_type":{  
                    "type":"string"
                 },
                 "content_length":{  
                    "type":"integer"
                 },
                 "language":{  
                    "type":"string"
                 }
              }
           },
           "id":{  
              "type":"double",
              "store":true
           },
           "lastModifiedDate":{  
              "type":"date",
              "store":true,
              "format":"strict_date_optional_time||epoch_millis"
           },
           "title":{  
              "type":"string",
              "store":true,
              "term_vector":"with_positions_offsets"
           }
        }
     }
  },
  "settings":{  
     "index":{  
        "creation_date":"1466180794989",
        "analysis":{  
           "filter":{  
              "nGram":{  
                 "min_gram":"2",
                 "side":"front",
                 "type":"edge_ngram",
                 "max_gram":"20"
              }
           },
           "analyzer":{  
              "partial":{  
                 "filter":[  
                    "standard",
                    "asciifolding",
                    "lowercase",
                    "snowball"
                 ],
                 "type":"custom",
                 "tokenizer":"nGram"
              },
              "full":{  
                 "filter":[  
                    "standard",
                    "asciifolding",
                    "lowercase",
                    "snowball",
                    "nGram"
                 ],
                 "type":"custom",
                 "tokenizer":"standard"
              }
           }
        },
        "number_of_shards":"5",
        "number_of_replicas":"1",
        "uuid":"tc-yTpbIQGeGDMOOMspf_g",
        "version":{  
           "created":"2030399"
        }
     }
  },
  "warmers":{  

  }
 }
 }

我也试过了stemmer_override。但没有运气

1 个答案:

答案 0 :(得分:0)

我发现了这个问题。分析器未设置为附件字段。

 var fullNameFilters = new List<string> { "lowercase", "snowball" };
        client.CreateIndex("mydocs", c => c
              .Settings(st => st
                        .Analysis(anl => anl
                        .Analyzers(h => h
                            .Custom("full", ff => ff
                                 .Filters(fullNameFilters)
                                 .Tokenizer("standard"))
                            )
                            .TokenFilters(ba => ba
                                .Snowball("snowball", sn => sn
                                    .Language(SnowballLanguage.English)))                    
                             ))
                         .Mappings(mp => mp
                         .Map<IndexDocument>(ms => ms
                         .AutoMap()
                         .Properties(ps => ps
                             .Nested<Attachment>(n => n
                                 .Name(sc => sc.File)
                             .AutoMap()
                             ))
                        .Properties(at => at
                        .Attachment(a => a.Name(o => o.File)
                        .FileField(fl=>fl.Analyzer("full"))
                        .TitleField(t => t.Name(x => x.Title)
                        .Analyzer("full")
                        .TermVector(TermVectorOption.WithPositionsOffsets)
                        )))

                        ))                        
                        );

和http:localhost:9200 / mydocs返回

{  
 "mydocs":{  
    "aliases":{  

  },
  "mappings":{  
     "indexdocument":{  
        "properties":{  
           "docLocation":{  
              "type":"string",
              "index":"not_analyzed",
              "store":true
           },
           "documentType":{  
              "type":"string",
              "store":true
           },
           "file":{  
              "type":"attachment",
              "fields":{  
                 "content":{  
                    "type":"string",
                    "analyzer":"full"
                 },
                 "author":{  
                    "type":"string"
                 },
                 "title":{  
                    "type":"string",
                    "term_vector":"with_positions_offsets",
                    "analyzer":"full"
                 },
                 "name":{  
                    "type":"string"
                 },
                 "date":{  
                    "type":"date",
                    "format":"strict_date_optional_time||epoch_millis"
                 },
                 "keywords":{  
                    "type":"string"
                 },
                 "content_type":{  
                    "type":"string"
                 },
                 "content_length":{  
                    "type":"integer"
                 },
                 "language":{  
                    "type":"string"
                 }
              }
           },
           "filePermissionInfo":{  
              "properties":{  
                 "accessControlType":{  
                    "type":"string",
                    "store":true
                 },
                 "accountValue":{  
                    "type":"string",
                    "store":true
                 },
                 "fileSystemRights":{  
                    "type":"string",
                    "store":true
                 },
                 "isInherited":{  
                    "type":"string",
                    "store":true
                 }
              }
           },
           "id":{  
              "type":"double",
              "store":true
           },
           "lastModifiedDate":{  
              "type":"date",
              "store":true,
              "format":"strict_date_optional_time||epoch_millis"
           },
           "title":{  
              "type":"string",
              "store":true,
              "term_vector":"with_positions_offsets"
           }
        }
     }
  },
  "settings":{  
     "index":{  
        "creation_date":"1466482894271",
        "analysis":{  
           "filter":{  
              "snowball":{  
                 "type":"snowball",
                 "language":"English"
              }
           },
           "analyzer":{  
              "full":{  
                 "filter":[  
                    "lowercase",
                    "snowball"
                 ],
                 "type":"custom",
                 "tokenizer":"standard"
              }
           }
        },
        "number_of_shards":"5",
        "number_of_replicas":"1",
        "uuid":"PpxcRl29QTCPtFcsd3PHtw",
        "version":{  
           "created":"2030399"
        }
     }
  },
  "warmers":{  

  }
  }
 }