从Elasticsearch检索数据时,请删除停止字或排除列表

发布于 2025-02-08 09:22:50 字数 1303 浏览 2 评论 0原文

  • 我需要删除停止单词和一些单词以排除以搜索
  • 如果我在搜索喜剧时,我不应该在排除列表中获得任何内容,我在
  • 停止词中添加 了喜剧无论我进行正常搜索,都应匹配
  • ,我应该返回存在的值。就像im搜索jennifer
  • 现在,如果im搜索 im for uptuff现在,停止词对我不起作用,但是我不应该
  • 使用query> query_string < /code>仅在我的DSL查询

[{'ID':0,'title':'live1','us gross':146083,'Worldwide Gross':146083,'US DVD销售':无,'生产预算':8000000,“发布日期”:“ 1998年6月12日”,'mpaa评级':'r',“运行时间min”:note类型':喜剧,“创意类型”:无,'导演':T and I,“腐烂的西红柿评级”:无,'imdb评级':6.1,'imdb票':1071},{'id'':1 ,, 1 ,, 1 ,, 1 ,, “标题”:“初恋,最后的礼仪”,“美国总体”:10876,“全球票房”:10876,'US DVD销售':无,“生产预算”:300000,“发布日期”:'8月7日1998年8月7日','mpaa rating':'r','running timer min':none,“分销商”:'strand',“ source':none,“主要类型”:“戏剧”,“创意类型”:none,none,'导演':理查德·詹妮弗(Richard Jennifer),“腐烂的西红柿等级”:无,'imdb评分':6.9,'imdb票':207}]

设置在

settings =   {
 "settings": {
   "analysis": {
     "analyzer": {
       "blogs_analyzer": {
         "type": "standard",
         "stopwords": ["and", "is","comedy"]
       }
     }
   }
 }
}

我的DSL查询下方,在下面

{
"query": {
    "bool": {
      "must": {
        "query_string": {
          "query": "and",
          "fields": ["Title^24",
            "Major Genre^8","Director^2" ]
        }
      }
    }
  }}
  • I need to remove stop words and some words to exclude to search
  • if i m searching for comedy i should not get anything since its in exclusion list, i have added comedy in stopwords
  • what word i have added in stop words then i should not get that if it's matches irrespective of
  • if i am doing normal search then i should return the values present. like if i m searching for Jennifer
  • RIght now stopwords is not working for me, if i m searching and i m getting output, but i should not
  • I have to use query_string only in my dsl query

[ { 'id': 0, 'Title': 'Live1', 'US Gross': 146083, 'Worldwide Gross': 146083, 'US DVD Sales': None, 'Production Budget': 8000000, 'Release Date': 'Jun 12 1998', 'MPAA Rating': 'R', 'Running Time min': None, 'Distributor': 'Gramercy', 'Source': None, 'Major Genre': Comedy, 'Creative Type': None, 'Director': T and I, 'Rotten Tomatoes Rating': None, 'IMDB Rating': 6.1, 'IMDB Votes': 1071 }, { 'id': 1, 'Title': 'First Love, Last Rites', 'US Gross': 10876, 'Worldwide Gross': 10876, 'US DVD Sales': None, 'Production Budget': 300000, 'Release Date': 'Aug 07 1998', 'MPAA Rating': 'R', 'Running Time min': None, 'Distributor': 'Strand', 'Source': None, 'Major Genre': 'Drama', 'Creative Type': None, 'Director': Richard Jennifer, 'Rotten Tomatoes Rating': None, 'IMDB Rating': 6.9, 'IMDB Votes': 207 }]

settings is below

settings =   {
 "settings": {
   "analysis": {
     "analyzer": {
       "blogs_analyzer": {
         "type": "standard",
         "stopwords": ["and", "is","comedy"]
       }
     }
   }
 }
}

My Dsl query is below

{
"query": {
    "bool": {
      "must": {
        "query_string": {
          "query": "and",
          "fields": ["Title^24",
            "Major Genre^8","Director^2" ]
        }
      }
    }
  }}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里寻她 2025-02-15 09:22:50

似乎您已经创建了blogs_analyzer,但没有分配到任何字段。因此,它将考虑标准分析仪。

您需要使用下面的配置创建索引映射,然后不会给您带来结果:

{
  "settings": {
    "analysis": {
      "analyzer": {
        "blogs_analyzer": {
          "type": "standard",
          "stopwords": [
            "and",
            "is",
            "comedy"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "Title": {
        "type": "text",
        "analyzer": "blogs_analyzer"
      },
      "Director": {
        "type": "text",
        "analyzer": "blogs_analyzer"
      },
      "Major Genre": {
        "type": "text",
        "analyzer": "blogs_analyzer"
      }
    }
  }
}

上述配置后,可以重新索引数据并使用以下查询搜索:

{
  "query": {
    "query_string": {
      "fields": ["Title","Director","Major Genre"], 
      "query": "and"
    }
  }
}

It seems like you have created blogs_analyzer but not assign to any of the field. So it will consider standard analyzer.

You need to create index mapping with below configuration and then it will not give you result:

{
  "settings": {
    "analysis": {
      "analyzer": {
        "blogs_analyzer": {
          "type": "standard",
          "stopwords": [
            "and",
            "is",
            "comedy"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "Title": {
        "type": "text",
        "analyzer": "blogs_analyzer"
      },
      "Director": {
        "type": "text",
        "analyzer": "blogs_analyzer"
      },
      "Major Genre": {
        "type": "text",
        "analyzer": "blogs_analyzer"
      }
    }
  }
}

After above configuration, you can reindex your data and search with below query:

{
  "query": {
    "query_string": {
      "fields": ["Title","Director","Major Genre"], 
      "query": "and"
    }
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文