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

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

我们可以搜索特定文档中的所有单词,如下所示:

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

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

这将搜索单词 Black , Nike 和在标题的字段中,只有那些将在标题中具有所有这些单词的文档才会返回 字段。

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.

但是我想做的是有所不同。

But what I am trying to do is a little different.

我想要查找,如果文档的标题字段中的所有单词都存在于我的搜索查询中,那么它将返回该文档。

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.

对于例如

假设有一个标题的文档:Nike Free Sparq Mens White在弹性搜索数据库中

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

现在,如果我使用查询搜索:Nike Free Sparq 09 - Mens - White / Black / Varsity Red / code>那么它应该返回这个文档,因为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

中,但如果我使用查询进行搜索:Nike Free Lebron - 男士 - 白色/黑色然后它不应该返回文档,因为我的查询单词 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!

这是我做的:

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

    这对我来说非常有用!

    除非有人从弹性搜索查询语言获得直接的方法。

    Unless someone has a direct method from elasticsearch query language.

更多推荐

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

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

发布评论

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

>www.elefans.com

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