How to search on multiple words and need to start with the given letter


(anusha) #1

Hi All,

I declared my settings with analyzer as,
"analyzer_startswith": {
"filter": [
"lowercase"
],
"tokenizer": "whitespace"
}

And kept my mappings as:

"ast": {
"mappings": {
"ast_type": {
"properties": {
"id": {
"type": "string",
"analyzer": "analyzer_startswith"
},
"name": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}

And am using the following query for to get the results with '1' as starting
GET ast/ast_type/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"id":
{ "query": "1",
"operator": "and"
}

               }
           }
        ]
    }
}

}

But am getting only mobil 1 as a result...

If I changes the query as with 'type: 'phrase_prefix'
"match": {
"id":
{ "query": "1",
"operator": "and",
"type": "phrase_prefix"
}

Then I can able to get all the records having 1.
If I give the query as
"match": {
"id":
{ "query": "1 mobil",
"operator": "and",
"type": "phrase_prefix"
}
Am getting no results, May I know what exactly it is happening and also the query which is suitable to my requirement

  1. the word starts with the letter that I enetered ,
  2. If I enter any order of words like 'mobil 1' and '1 mobil' would like to get the result.........

(anusha) #2

Need this immediately, which is an urgent requirement... Fast response is appreciable..


(David Pilato) #3

What is so urgent that you post a follow up just after 13 minutes?
I mean: is you cluster in production totally down that you can't wait for the community to help you once someone has time?

BTW, try to correctly format your question to make it more readable.
Also, I would suggest that you provide a full running script if you want someone to pick it up and try to fix it.
There is no example here of what you have indexed.


(anusha) #4

Hi David,

May I know what information you need to trace it out, any sample data if you need then,

{
"id":"12304",
"name":"12304"
}, in this way I have few records with starting 1 as 10W10, 10W20, 1212, 15W40 where id and name will be same values,
I would like to search only in id field...
So when am entering 1 in match query am not getting any results only when I include 'type': 'phrase_prefix' am getting data.


(anusha) #5

In my sample data I have two records as:
{
id: mobil 1,
name: mobil 1
}

I have tried with query which I mentioned above the first query, without 'phrase_prefix' ---> for this I got no result..
If am trying the query including 'type':'phrase_prefix' am getting the result ( with 'query':'1')
If am entering one more word like
"match": {
"id":
{ "query": "1 m",
"operator": "and",
"type": "phrase_prefix"
}---> no results am able to get

If I give the query order as 'query': 'mobil 1',--> able to get record with mobil 1
But with reverse order the query is not working..'query': '1 mobil'---> no records..

So how can I achieve the result even the string order may be anything like '1 mobil' or 'mobil 1'??


(system) #6