Gor
Gor

Reputation: 2908

elasticsearch full text search part of word

How can I query on elasticsearch for full text searching by part of word.

For example if I have these documents

{
    name: "A1"
    desc: "This is first document"
}
{
    name: "A2"
    desc: "This is second document"
}

When I search like this

{
    query: {
        query_string: {
            query: 'first'
        }
    }
}

It returns me first document, but when I try to search

{
    query: {
        query_string: {
            query: 'fir'
        }
    }
}

It doesnt return anything. How can I solve this without mapping parameters such as ngrams, just with query.

Thank you

Upvotes: 1

Views: 625

Answers (1)

Val
Val

Reputation: 217314

You should try with a wildcard instead, like this, it will work.

{
    query: {
        query_string: {
            query: 'fir*'
        }
    }
}

Otherwise, use ngrams, it's much more performant.

Upvotes: 2

Related Questions