【问题标题】:Match query returns nothing匹配查询不返回任何内容
【发布时间】:2019-07-26 01:47:20
【问题描述】:

我想在字段中搜索文本。

我试图通过this documentation 解决我的问题

我的一个索引包含以下结构的项目:

{
    url: "https://exampleurl.com"
    username: "some_username"
}

这是我的问题:

"query": {
    "multi_match":  {
        "query": keyword,
        "type": "phrase",
        "fields": [ "username", "url" ]
    }

}

还有布尔查询:

"query": {
    "bool": {
        "must": {
            "multi_match":  {
                 "query": keyword,
                 "type": "phrase",
                 "fields": [ "username", "url" ]
            }
        },
    }
}

"query": {
"bool": {  
    "must": [{
        "match": {
            "username": keyword,
        }
     }, {
        "match": {
            "url": keyword
        }
    }]
}
}

但是结果是一个空数组

【问题讨论】:

  • 请分享索引定义。您定义的索引字段类型以及您尝试搜索的确切查询,以便我们提供帮助。
  • @dassum 我提供了我的索引字段和查询的示例..

标签: python elasticsearch


【解决方案1】:

请尝试以下查询。

  1. 创建索引
    PUT test
    {
        "settings" : {
            "number_of_shards" : 1
        },
        "mappings" : {
            "properties" : {
                "url" : { "type" : "text" },
                "username" : { "type" : "text" }

            }
        }
    }
  1. 插入文档
    PUT test/_doc/1
    {
        "url" : "https://exampleurl.com",
        "username" : "Arjun Das"    
    }
  1. 搜索

    GET test/_search
    {
    "query": {
        "multi_match":  {
            "query": "http",
            "type": "best_fields",
            "fields": [ "username", "url" ],
            "fuzziness":"2"

        }
    }
    }

【讨论】:

    猜你喜欢
    • 2012-04-14
    • 1970-01-01
    • 2021-04-24
    • 2013-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多