elasticsearch - 应用match_phrase和filter

标签 elasticsearch

在Elastic Search 6.4.2上工作。我想使用match_pharse从索引中检索结果。同样,我需要为此应用过滤器。任何解决方案。我尝试了以下查询

{
  "query": {
    "bool": {
      "should": 
        {
          "match_phrase": {
          "title": "bike riding"
          }}

    }
  }}

但是,当我使用match_pharse时,我需要传递字段以获取结果。我正在共享需要编辑的映射和查询。我可以使用match_phrase进行查询的任何帮助。

对应:
{
  "mapping": {
    "doc": {
      "properties": {
        "content": {
          "type": "text",
          "store": true,
          "analyzer": "my_analyzer"
        },
        "description": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "domain": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "host": {
          "type": "keyword",
          "store": true
        },
        "keywords": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "seed": {
          "type": "keyword",
          "store": true
        },
        "title": {
          "type": "text",
          "store": true,
          "analyzer": "my_analyzer"
        },
        "url": {
          "type": "text",
          "store": true
        }
      }
    }
  }
}`

查询:
如何将match_phrase添加到下面的一个
{
    "query": {
        "bool" : {
            "must" : {
                "query_string" : {
                    "query" : "bike riding"
                }
            },
            "filter" : {
                "term" : { "seed" : "sports" }
            }
        }
    }
}

最佳答案

下面的查询是您想要的。

注意我如何在"\"bike riding\""周围添加引号

POST <your_index_name>/_search
{
  "query": {
        "bool" : {
            "must" : {
                "query_string" : {
                    "query" : "\"bike riding\""
                }
            },
            "filter" : {
                "term" : { "seed": "sports" }
            }
        }
    }

}

让我知道是否有帮助!

关于elasticsearch - 应用match_phrase和filter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53267300/

相关文章:

elasticsearch - 集成测试中嵌入式ElasticSearch无法连接到传输端口

elasticsearch - 如何使用Filebeat配置RabbitMQ

docker - 用于Docker的Kibana的NginX反向代理

elasticsearch - Elastic Search 忽略 `token_chars`

elasticsearch - 在Kibana 4中显示多行

elasticsearch - ES-6 .1。 - 如何更改默认的碎片数量

elasticsearch - 将旧数据从Elasticsearch存档到Google Cloud Storage

elasticsearch - Terraform:在 ElasticSearch 中设置 max_buckets

elasticsearch - 在 Elasticsearch 中使用过滤器查询聚合嵌套字段

php - _score,同时在Elasticsearch中进行索引