ES查询常用语法
    		       		warning:
    		            这篇文章距离上次修改已过443天,其中的内容可能已经有所变动。
    		        
        		                
                在Elasticsearch中,查询是通过JSON格式的DSL(Domain Specific Language)来表示的。以下是一些常见的查询类型和相应的JSON查询语句示例:
- 全文查询(Full text search):
{
  "query": {
    "match": {
      "field": "text to search"
    }
  }
}- 多字段全文查询(Multi-field full text search):
{
  "query": {
    "multi_match": {
      "query": "text to search",
      "fields": ["field1", "field2"]
    }
  }
}- 精确匹配查询(Term level search):
{
  "query": {
    "term": {
      "field": {
        "value": "exact value"
      }
    }
  }
}- 范围查询(Range query):
{
  "query": {
    "range": {
      "field": {
        "gte": 10,
        "lte": 20
      }
    }
  }
}- 复合查询(Compound query):
{
  "query": {
    "bool": {
      "must": [
        { "match": { "field1": "value1" } },
        { "match": { "field2": "value2" } }
      ],
      "filter": [
        { "term": { "field3": "value3" } }
      ]
    }
  }
}- 高亮查询结果(Highlighting search results):
{
  "query": {
    "match": {
      "field": "text to search"
    }
  },
  "highlight": {
    "fields": {
      "field": {}
    }
  }
}- 排序(Sorting):
{
  "query": {
    "match_all": {}
  },
  "sort": [
    { "field": "asc" },
    { "other_field": "desc" }
  ]
}- 分页(Pagination):
{
  "query": {
    "match_all": {}
  },
  "from": 10,
  "size": 10
}这些是Elasticsearch查询中的基本构建块,可以根据需要组合使用以创建更复杂的查询。
评论已关闭