elasticsearch匹配搜索查询中的文档中的所有单词 [英] elasticsearch match all words from document in the search query

查看:293
本文介绍了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匹配搜索查询中的文档中的所有单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆