elasticsearch 匹配搜索查询中文档中的所有单词

编程入门 行业动态 更新时间:2024-10-27 12:37:24
本文介绍了elasticsearch 匹配搜索查询中文档中的所有单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们可以像这样搜索特定文档字段中的所有单词:

We can search for ALL words in a specific document.field like this:

{ "query" : { "match" : { "title": { "query" : "Black Nike Mens", "operator" : "and" } } } }

这将在 title 字段中搜索词 Black、Nike 和 Mens,这样只有那些返回的文档将在 title 字段中包含所有这些单词.

This will search for the words Black, Nike and Mens in the field title such that only those documents are returned that will have ALL these words in the title field.

但我想做的有点不同.

我想这样查找,如果文档的 title 字段的所有单词都出现在我的搜索查询中,那么它将返回该文档.

I want to lookup such that if all the words of the title field of the document are present in my search query then it will return that document.

例如

假设在elasticsearch数据库中有一个title:Nike Free Sparq Mens White"的文档

suppose there is a document with title : "Nike Free Sparq Mens White" in the elasticsearch database

现在,如果我使用 query 进行搜索:Nike Free Sparq 09 - Mens - White/Black/Varsity Red" 那么它应该返回这个文档,因为 document.title 中的所有单词都可以存在于我的查询中

now if I search with a query : "Nike Free Sparq 09 - Mens - White/Black/Varsity Red" then it should return this document, because all the words in the document.title do exist in my query

但是如果我使用 query 进行搜索:Nike Free Lebron - Mens - White/Black" 那么它不应该返回文档,因为我的查询包含 Sparq失踪

but if I search with a query : "Nike Free Lebron - Mens - White/Black" then it should NOT return the document because my query has the word Sparq missing

这是一种反向运算符搜索

this is a sort of reverse-and-operator search

这可能吗?如果是,那么如何?

Is this possible? If yes, then how?

推荐答案

我终于让它工作了,但不是用直接的方法!

I finally got it to work but not with a direct method!

这就是我所做的:

  • 从源查询中创建一个干净的单词列表,方法是:
    • 改为小写
    • 用空格替换任何特殊字符和标点
    • 删除重复的单词

    这对我来说效果很好!

    除非有人有来自elasticsearch查询语言的直接方法.

    Unless someone has a direct method from elasticsearch query language.

更多推荐

elasticsearch 匹配搜索查询中文档中的所有单词

本文发布于:2023-11-22 20:19:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1618872.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单词   文档   elasticsearch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!