Home > OS >  Elastic search with query_string, wild card and type
Elastic search with query_string, wild card and type

Time:09-20

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?

CodePudding user response:

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.

CodePudding user response:

{
   "_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!            
  • Related