如何在elasticsearch 7.7.0及更高版本中进行精确的子字符串匹配

d5vmydt9  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(0)|浏览(316)

这是我的es索引

PUT /recharge
{
  "mappings": {
      "properties": {
        "word": {"type": "text"},
        "varients": {
          "type": "object",
          "properties": {
            "w": {"type": "text"}
        }
      }
    }
  }
}
POST recharge/_doc/1
{
  "word": "International roaming",
  "varients": [
    {
      "w": "international roaming"
    }
  ]
}

POST recharge/_doc/2
{
  "word": "domestic roaming",
  "varients": [
    {
      "w": "domestic roaming"
    },
    {
      "w": "roaming"
    }
  ]
}

我将以下查询发送到我的ElasticSearch并获得以下输出

GET recharge/_search
{
  "query": {
    "multi_match": {
      "query": "I want International roaming pack for my number",
      "fields": ["varients.w", "word"]
    }
  }
}

在输出结果中,我得到

{"title": "Domestic roaming"}
{"title": "International roaming"}

在字符串匹配的情况下,我不需要两个输出,而是只需要与查询部分完全匹配的字符串。即。 {"title": "International roaming"} 我只需要从以下查询部分进行精确搜索: I require international roaming packs{"title": "International roaming"}I require domestic roaming packs ```
{"title": "Domestic roaming"}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题