ElasticSearch(十) Full Text Queries API

一、matchAllQuery 查询所有
match query 全文查询的标准查询,包括模糊匹配和短语或近距离查询,match查询接受文本/数字/日期,分析他们,并构件查询。
matchQuery(
        "name",  "kimchy elasticsearch"); 
{
  "query": {
    "match": {
        "content" : {
            "query" : "我的宝马多少马力"
        }
    }
  }
}

上面的查询匹配就会进行分词,比如"宝马多少马力"会被分词为"宝马 多少 马力", 所有有关"宝马 多少 马力", 那么所有包含这三个词中的一个或多个的文档就会被搜索出来。
并且根据lucene的评分机制(TF/IDF)来进行评分。

二、multi_match query  对多字段执行相同查询
multiMatchQuery(
        "kimchy elasticsearch", "user", "message");  
{
    "multi_match": {
        "query":                "Quick brown fox",
        "type":                 "best_fields", 
        "fields":               [ "title", "body" ],
        "tie_breaker":          0.3,
        "minimum_should_match": "30%" 
    }
}
三、query_string query 字符查询
queryStringQuery("+kimchy -elasticsearch");

{
"query_string":{
"default_field":"name",
"query":"(this AND that) OR thu*"
}

}
query: 需要查询的具体内容
default_field: 查询的字段
默认是_all,即对所有字段进行查询。

支持多字段——"fields" : ["age", "name"],fields中只要有一个字段满足query的条件即可匹配查询。

支持一些简单的wildcard写法。比如fields:[“nam*”]即任何nam开头的字段,注意:如果field与query写在一起比如”query”:”name:obama”,要使用wildcard需要转义--->”query”:”nam\*:obama”

四、simple_query_string
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html


原文地址:https://www.cnblogs.com/xiaocandou/p/8119541.html