1

I have a problem with ElasticSearch query phrases. My index document is;

    var person = new Person
    {
        Id = "4",
        Firstname = "ali ahmet",
        Lastname = "yazıcı"
    };
    var index = client.Index(person, x => x.Index("personindex"));

My search phrase is;

    var result = client.Search<Person>(s => s
        .From(0)
        .Size(10)
        .Query(q => q
            .SimpleQueryString(qs => qs
                .OnFields(new[]{"firstname","lastname"})
                .Query("\"ali ah*\"")
            )
        )
  );

Result document is empty. But when i change my phrase to

.Query("\"ali ahmet\"")

result is coming. Why return empty result from

.Query("\"ali ah*\"")

this phrase.

EDIT

Person Class

public class Person
{
    public string Id { get; set; }
    public string Firstname { get; set; }
    public string Lastname { get; set; }
}

Index mapping

var response = client.CreateIndex("personindex", c => c
            .AddMapping<Person>(m => m.MapFromAttributes())
1
  • May you share index mapping and Person class as well? Commented Aug 23, 2015 at 15:05

2 Answers 2

1

From documentation for simple query string:

" wraps a number of tokens to signify a phrase for searching

When you are searching for .Query("\"ali ah*\"") actually it looks for phrase ali ah*, but * is not treated as wildcard character.

Chnage your NEST query to:

var result = client.Search<Person>(s => s
    .Explain()
    .From(0)
    .Size(10)
    .Query(q => q
        .QueryString(qs => qs
            .OnFields(new[] {"firstname", "lastname"})
            .Query("ali ah*")
        )
    ));

Hope it helps.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Rob. But your query is equals with "ali or ah*" match. I don't want this. Word order is very important for me. First word must "ali" and second word is "ah*".
0
var result = client.Search<Person>(s => s
.Explain()
.From(0)
.Size(10)
.Query(q => q
    .Match(qs => qs
        .OnFields(new[] {"firstname", "lastname"})
        .Query("ali ah*")
        .MinimumShouldMatch(100)
    )
));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.