Elastic search with query_string, wild card and type

Viewed 24

Why doesn't this work properly?

{
   "query_string": {
       "fields": ["text"],
       "query":  "for*t drink",
       "type": "phrase"
   }
}

I wanted this to return the documents that have those 2 words atleast, with no gaps between them and with the same order, it looks like its completely ignoring the phrase type, if I pass the default_operator: "AND", it kinda works but I still have the problem with the gaps and the order. Is it possible to do this? Another question if my mapping of the text look like this:

Text properties:

            "text": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                    
                },
                "analyzer": "my_text_analyzer"
            },

Analyzer:

"my_text_analyzer": {
                    "type": "custom",
                    "tokenizer": "whitespace",
                    "filter": [
                        "lowercase",
                        "asciifolding"
                    ]
                }

Is it possible to make a request to return exact data, make it case sensisitive when requested and when not case sensitive when needed?

2 Answers

You are using the analyzer which is splitting tokens on whitespace than its not possible for phrase query to give results matching multiple words like foo bar or for*t drink.

Can you query instead of text to text.keyword.

{
   "_index": "allposts",
   "_type": "_doc",
   "_id" : xxx
   _source: {
      "text": "[Eng] I am back, I think .Doing some Soloq Ranked, come watch and don't forget to hit the follow button.\n[PT] Estou de volta, acho eu. Estou a fazer Soloq Ranked, anda ver e não te esqueças de dar follow na stream.\nwww.twitch.tv/Yenthii",
   }
},
{
"_index": "allposts",
   "_type": "_doc",
   "_id" : xxx
   _source: {
      "text": "Today we embrace the Serpent's Embrace! \n\nCan't forget to wish the deadly Cassiopeia a happy bday today! "
   }
},
{
"_index": "allposts",
   "_type": "_doc",
   "_id" : xxx
   _source: {
      "text": "Our fixtures with Nottingham Forest and Swansea City in February have been selected for live television coverage ",
   }
},
{
"_index": "allposts",
   "_type": "_doc",
   "_id" : xxx
   _source: {
       "text": "Believe me, Marty, you‘re better off not having to worry about all the aggravation and headaches of playing at that dance. I followed you. Well maybe you are and you just don‘t know it yet. Thank you, don‘t forget to take a flyer. Hello.\n\nIts good. Yeah, gimme a Tab. Shut your filthy mouth, I‘m not that kind of girl. Marty, such a nice name. Yeah I know, If you put your mind to it you could accomplish anything.",
   }
},


If my query is like bellow, I don't want it show anything

{
                    "query_string": {
                        "fields": ["text.keyword"],
                        "query":  "for*t flyer",
                        "type": "phrase"
                    }
}

If the query is like the bellow I want the 4 posts

{
                    "query_string": {
                        "fields": ["text.keyword"],
                        "query":  "for*t to",
                        "type": "phrase"
                    }
}
Related