如何使用ElasticSearch在字符串字段中搜索完整的短语? [英] How to search exact phrase in string field with ElasticSearch?

查看:512
本文介绍了如何使用ElasticSearch在字符串字段中搜索完整的短语?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在文档中搜索社交网络营销。全部一起。但我继续得到结果与单词分离。我有以下DSL查询:

I want to search "Marketing in social networks" inside documents. All together. But i continue getting results with words separated. i have the following DSL query:

{
    "fields": ["title"], 
    "query": {
        "bool": {
            "should": [{
                "match": {
                    "title": "SEO"
                }
            }],
            "must": [{
                "match": {
                    "content": {
                        "query": "Marketing in social networks",
                        "operator": "and"
                    }
                }
            }]
        }
    }
}

我没有包含此短语和标题的文档,但我也可以使用短语的单词来搜索分割的结果(文档)。我想要严格的搜索。如果没有任何具有此短语的文档不能检索任何文档或仅检索具有该标题的文档。
为什么运算符和不起作用?

I do not have documents that contain this phrase and title but i also get results(documents) with the words of the phrase to search splitted. I want a strict search. If there is not any document that have this phrase do not retrieve any document or only retrieve documents with that title. Why operator and does not work?

推荐答案

短语。请参阅此处


查询首先分析查询字符串以产生术语列表。它
然后搜索所有条款,但只保留包含
的所有搜索字词的文档在相对于彼此相同的位置

query first analyzes the query string to produce a list of terms. It then searches for all the terms, but keeps only documents that contain all of the search terms, in the same positions relative to each other



{
    "fields": ["title"], 
    "query": {
        "bool": {
            "should": [{
                "match": {
                    "title": "SEO"
                }
            }],
            "must": [{
                "match": {
                    "content": {
                        "query": "Marketing in social networks",
                        "type":  "phrase"
                    }
                }
            }]
        }
    }
}

PS:我还没有尝试过。

P.S: I haven't tried it yet.

这篇关于如何使用ElasticSearch在字符串字段中搜索完整的短语?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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