具有查询字符串、通配符和类型的ElasticSearch

myss37ts  于 2022-09-20  发布在  ElasticSearch
关注(0)|答案(2)|浏览(198)

为什么这不能正常工作?

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

我想让它返回至少包含这两个单词的文档,它们之间没有空格,并且顺序相同,看起来它完全忽略了短语类型,如果我传递DEFAULT_OPERATOR:“AND”,它有点工作,但我仍然有空格和顺序的问题。能做到这一点吗?如果我的文本Map如下所示,另一个问题是:

文本属性:

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

                },
                "analyzer": "my_text_analyzer"
            },

分析器:

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

是否可以发出返回准确数据的请求,使其在请求时区分大小写,而在需要时不区分大小写?

uqzxnwby

uqzxnwby1#

您使用的分析器在空格上拆分标记,而短语查询不可能给出匹配多个单词(如foo barfor*t drink)的结果。

可以用text代替text.keyword查询吗?

ekqde3dh

ekqde3dh2#

{
   "_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! 💖nnCan'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.nnIts 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.",
   }
},

如果我的查询如下图所示,我不希望它显示任何内容

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

如果查询像下面这样,我想要这4个帖子

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

相关问题