Skip to content

MehdiMst00/ElasticsearchSample

Repository files navigation

Elasticsearch Sample

Elasticsearch sample for asp.net core

Setup Elasticsearch and Kibana using docker compose

docker compose -f ./docker-compose-dev.yaml up -d

Full-Text Implementation Sample

public async Task<List<Product>> SearchProducts(string query)
{
    var client = elasticsearchService.Client;

    var searchResponse = await client.SearchAsync<Product>(s => s
        .Index(_indexName)
        .Query(q => q
            .FunctionScore(fs => fs
                .Query(q => q
                    .MultiMatch(mm => mm
                        .Query(query)
                        .Fields("name")
                        .Type(TextQueryType.BestFields)
                        .Fuzziness(new Fuzziness(1))
                        .MinimumShouldMatch("75%")
                    )
                )
                .BoostMode(FunctionBoostMode.Multiply)
            )
        )
    );
    
    return [.. searchResponse.Documents];
}

About

Elasticsearch asp.net core sample

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages