[Fine] elasticsearch learning and practice (second lecture)

Comparison of various search methods

1、query string search
2、query DSL
3、query filter
4、full-text search
5、phrase search
6、highlight search

Search all products: GET /ecommerce/product/_search
took: took a few milliseconds
timed_out: is it timed out, here is no
_shards: data is split into 5 shards, so for search requests, all primary shards (or It can also be a replica shard of it)
hits.total: the number of query results, 3 documents
hits.max_score: the meaning of the score, which is the matching score of the document's relevance to a search, the more relevant, the more matching, score Also high
hits.hits: contains detailed data of documents matching the search

#Check es status 
GET _cat/health?v #Check
all indexes 
GET _cat/indices?v

PUT /ecommerce/product/4
{
  "name": "special yagao",
  "desc": "special meibai",
  "price" : 50,
  "producer": "special yagao producer",
  "tags": [
    "meibai"
  ]
}
#-------String------------------ ------------------------------------ #Query
all products 
GET /ecommerce/product/_search
#Query Items with the specified name and sorted in descending order by item price 
GET /ecommerce/product/_search?q=name:gaolujie&sort=price: desc
#-------DSL-------------------------------------- ----------------- #Query
all 
GET /ecommerce/product/_search
{
  "query": {"match_all": {}}
} #Query
all, only display name,price 
GET /ecommerce/product/_search
{
  "query": {"match_all": {}},
  "_source": ["name","price"]
} #Query the
specified name Product and sort by product price in descending order 
GET /ecommerce/product/_search
{
  "query": {"match": {
    "name": "yagao"
  }},
  "sort": [
    {
      "price":"desc"
    }
  ]
} #Pagination
query, query the first page
GET /ecommerce/product/_search
{
  "query": {"match_all": {}}, 
  "sort": [
    {
      "price": {
        "order":"desc"
      }
    }
  ], 
  "from": 0,
  "size": 1
}
#-------filter---------------------------------------- -----------------
#Search for products whose product name contains yagao and whose price is greater than 25
yuanGET /ecommerce/product/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "name": "yagao"
          }
        }
      ],
      "filter": {
        "range": {
          "price": {
            "gt":25
          }
        }
      }
    }
  }
}
#---------full-text------------------------------- ---------------------- #Full
text search (any match)
GET /ecommerce/product/_search
{
  "query": {
    "match": {
      "producer": "yagao producer"
    }
  }
}
#--------phrase-search------------------------------------------------
#短语检索(完全匹配 )
GET /ecommerce/product/_search
{
  "query": {
    "match_phrase": {
      "producer": "yagao producer"
    }
  }
}
#--------hight-lignt------------------------------------------------
#高亮搜索
GET /ecommerce/product/_search
{
  "query": {
    "match": {
      "producer": "producer"
    }
  },
  "highlight": {
    "fields": {
      "producer":{}
    }
  }
}

Guess you like

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