I am creating an index with the following code:
var ElasticSettings = new ConnectionSettings(new Uri(ConnectionString))
.DefaultIndex(_IndexName)
.DefaultMappingFor<PictureObject>(M => M
.Ignore(_ => _._id)
.Ignore(_ => _.Log))
.DefaultFieldNameInferrer(_ => _);
_ElasticClient = new ElasticClient(ElasticSettings);
if (!_ElasticClient.IndexExists(_IndexName).Exists)
{
var I = _ElasticClient.CreateIndex(_IndexName, Ci => Ci
.Settings(S => S
.Analysis(A => A
.CharFilters(Cf => Cf.Mapping("expressions",
E => E.Mappings(ExpressionsList))
)
.TokenFilters(Tf => Tf.Synonym("synonyms",
Descriptor => new SynonymTokenFilter
{
Synonyms = SynonymsList,
Tokenizer = "whitespace"
})
)
.Analyzers(Analyzer => Analyzer
.Custom("index", C => C
.CharFilters("expressions")
.Tokenizer("standard")
.Filters("synonyms", "standard", "lowercase", "stop")
)
.Custom("search", C => C
.CharFilters("expressions")
.Tokenizer("standard")
.Filters("synonyms", "standard", "lowercase", "stop")
)
)
)
)
.Mappings(Mapping => Mapping
.Map<PictureObject>(Map => Map
.AutoMap()
.Properties(P => P
.Text(T => T
.Name(N => N.Title)
.Analyzer("index")
.SearchAnalyzer("search")
)
.Text(T => T
.Name(N => N.Tags)
.Analyzer("index")
.SearchAnalyzer("search")
)
)
)
)
);
The fields I want to search are 'title' and 'tags'
My synonyms are in that format:
[
"big => large, huge",
"small => tiny, minuscule",
]
and my expressions are like:
[
"stormy weather => storm",
"happy day => joy",
]
When I do a search, I have tried these two methods:
var Test1 = _ElasticClient.Search<PictureObject>(S => S
.From(From)
.Size(Take)
.Query(_ => _.Fuzzy(Fuzz => Fuzz.Field(F => F.Tags).Field(T => T.Title).Value(Terms).MaxExpansions(2)))).Documents;
var resTest2 = _ElasticClient.Search<PictureObject>(S => S
.Query(_ => _.QueryString(F => F.Query(Terms)))
.From(From)
.Size(Take));
When trying to match terms exactly as they are in the tags field, the two functions return different results.
When trying to use synonyms, results vary again.
What am I missing?