I've been using elastic searh 5.5.0. And I've noticed that my sorting is not working properly. The results i get from search were not sorted as expected, they were being sorted on the basis of ascii value's.
Example:
Actual Output
Book
Chair
Table
board
cat
Expected Output
Book
board
Chair
cat
Table
I used analyzers with filter "lowercase" and "asciifolding" But failed to get the desired result.
I'm using NEST to implement this and here is the complete Method Implementation:
public static CreateIndexRequest GetIndexMapping(string index)
{
var newIndex = new CreateIndexRequest(index);
newIndex.Settings = new IndexSettings();
newIndex.Mappings = new Mappings();
newIndex.Settings.Analysis = new Analysis();
newIndex.Settings.Analysis.Analyzers = new Analyzers();
newIndex.Settings.Analysis.Normalizers = new Normalizers();
newIndex.Settings.Analysis.Analyzers.Add(Constant.ANALYZER, new CustomAnalyzer() { Tokenizer = "keyword", Filter = new List { "lowercase", "asciifolding" } });
newIndex.Settings.Analysis.Normalizers.Add("KeywordNormalizer", new CustomNormalizer() {Filter = new List { "lowercase", "asciifolding" } });
var indexTypes = new string[] { Constant.USER_TYPE, Constant.GROUP_TYPE, Constant.CONTACT_TYPE, Constant.COMPUTER_TYPE, Constant.OU_TYPE, Constant.HISTORY_TYPE };
foreach (var item in indexTypes)
{
var typeMapping = new TypeMapping();
typeMapping.DynamicTemplates = new DynamicTemplateContainer();
// text template
var stringTemplate = new DynamicTemplate();
stringTemplate.MatchMappingType = "string";
stringTemplate.Match = "*";
var property = new TextProperty() { Type = "text", Analyzer = Constant.ANALYZER, SearchAnalyzer = Constant.ANALYZER };
property.Fields = new Properties();
property.Fields.Add("keyword", new KeywordProperty() { Type = "keyword", IgnoreAbove = 1000});
stringTemplate.Mapping = property;
// long template
var longTemplate = new DynamicTemplate();
longTemplate.MatchMappingType = "long";
longTemplate.Match = "*";
var longProperty = new NumberProperty() { Type = "long" };
longProperty.Fields = new Properties();
longProperty.Fields.Add("keyword", new KeywordProperty() { Type = "keyword", IgnoreAbove = 1000});
longTemplate.Mapping = longProperty;
// bool template
var boolTemplate = new DynamicTemplate();
boolTemplate.MatchMappingType = "boolean";
boolTemplate.Match = "*";
var boolProperty = new BooleanProperty() { Type = "boolean" };
boolProperty.Fields = new Properties();
boolProperty.Fields.Add("keyword", new KeywordProperty() { Type = "keyword", IgnoreAbove = 1000});
boolTemplate.Mapping = boolProperty;
// binary template
typeMapping.DynamicTemplates.Add("ImanamiThumbnailTemplate", GetBinaryTemplate("*thumbnail*"));
typeMapping.DynamicTemplates.Add("ImanamiPhotoTemplate", GetBinaryTemplate("*photo*"));
typeMapping.DynamicTemplates.Add("ImanamiPictureTemplate", GetBinaryTemplate("*picture*"));
typeMapping.DynamicTemplates.Add("ImanamiStringTemplate", stringTemplate);
typeMapping.DynamicTemplates.Add("ImanamiLongTemplate", longTemplate);
typeMapping.DynamicTemplates.Add("ImanamiBoolTemplate", boolTemplate);
newIndex.Mappings.Add(item, typeMapping);
}
return newIndex;
}
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.