6 search interface -- 3 request body

There are certain limitations to using url for retrieval, that is, it is not suitable when there are many or complex conditions. In this case, the retrieval request can be written in the request body. (Because some open sources do not support the request body for get requests, you can use the post method)

{
    "from": 0,
    "size": 10,
    "query": {
        "bool": {
            "must": [
                {
                    "bool": {
                        "should": [
                            {
                                "term": {
                                    "status": 2
                                }
                            },
                            {
                                "term": {
                                    "tier": 3
                                }
                            }
                        ]
                    }
                },
                {
                    "term": {
                        "media_id": 102050
                    }
                }
            ],
            "should": [
                {
                    "term": {
                        "actions": 3
                    }
                }
            ],
            "must_not": [
                {
                    "term": {
                        "duration": "304"
                    }
                }
            ],
            "filter": [
                {
                    "range": {
                        "duration": {
                            "gte": 20,
                            "lt": 309
                        }
                    }
                },
                {
                    "range": {
                        "approved_time": {
                            "lt": 1486531465338
                        }
                    }
                }
            ]
        }
    },
    "sort": [
        {
            "duration": {
                "order": "desc"
            }
        },
        {
            "created_time": {
                "order": "desc"
            }
        }
    ]
}

The above is the summary Start

from 0, view 10
GET /_search
{
    "from" : 0, "size" : 10,
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}
Sort, ascending according to post_date
GET /my_index/my_type/_search
{
    "sort" : [
        { "post_date" : {"order" : "asc"}}
    ],
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}

asc: ascending
desc: descending
In addition, you can also sort according to complex types, but you need to define the definitions of complex types that need to be sorted

Field filtering (that is, those fields are not displayed, and those fields are displayed)
GET /_search
{
    "_source": "obj.*",
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}

or
GET /_search
{
    "_source": [ "obj1.*", "obj2.*" ],
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}

or
GET /_search
{
    "_source": {
        "includes": [ "obj1.*", "obj2.*" ],
        "excludes": [ "*.description" ]
    },
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}


Search for data where the color is red and the brand is gucci
GET /shirts/_search
{
  "query": {
    "bool": {
      "filter": [
        { "term": { "color": "red"   }},
        { "term": { "brand": "gucci" }}
      ]
    }
  }
}


Show the above data in groups
GET /shirts/_search
{
  "query": {
    "bool": {
      "filter": [
        { "term": { "color": "red"   }},
        { "term": { "brand": "gucci" }}
      ]
    }
  },
  "aggs": {
    "models": {
      "terms": { "field": "model" }
    }
  }
}

Highlight the content column
GET /_search
{
    "query" : {
        "match": { "content": "kimchy" }
    },
    "highlight" : {
        "fields" : {
            "content" : {}
        }
    }
}


Explain how scores are calculated
GET /_search
{
    "explain": true,
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}

version of the current document
GET /_search
{
    "version": true,
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}


Exclude score less than specified value
GET /_search
{
    "min_score": 0.5,
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326531709&siteId=291194637