1

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

Gor
  • 2,808
  • 6
  • 25
  • 46
  • Have you tried searching with a wildcard, i.e. `fir*` ? Out of curiosity, why don't you want to use ngrams? [See this](http://stackoverflow.com/questions/36706903/how-to-handle-wildcards-in-elastic-search-structured-queries) – Val Apr 19 '16 at 11:46
  • I cant use them because how I tried they doesnt work and I cant understand why, can you check If I send them ? – Gor Apr 19 '16 at 11:50
  • Of course, feel free to create another question with the ngram issue. – Val Apr 19 '16 at 11:51
  • @Val http://stackoverflow.com/questions/36717776/ngrams-ins-elasticsearch-are-not-working – Gor Apr 19 '16 at 12:02
  • Have you tried to use the wildcard above? – Val Apr 19 '16 at 12:04
  • Yes but I how I know wildcards cant be case insensitive. – Gor Apr 19 '16 at 12:05
  • Not sure I get you – Val Apr 19 '16 at 12:08
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/109545/discussion-between-gor-and-val). – Gor Apr 19 '16 at 12:09

1 Answers1

2

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.

Community
  • 1
  • 1
Val
  • 207,596
  • 13
  • 358
  • 360