ElasticSearch DSL 示例

阅读更多
PUT /megacorp/employee/4
{
  "first_name": "Jay",
  "last_name": "Smith",
  "age": 27,
  "about": "I love rock music",
  "interests": [
    "sports",
    "music"
  ]
}

POST /megacorp/employee
{
  "first_name": "Jay",
  "last_name": "Smith",
  "age": 27,
  "about": "I love rock music",
  "interests": [
    "sports",
    "music"
  ]
}

GET /megacorp/employee/_search
{
  "query": {
    "match": {
      "about": "cabinets"
    }
  }
}

GET /megacorp/employee/_search
{
  "query": {
    "match_phrase": {
      "about": "build cabinets"
    }
  }
}

GET /megacorp/employee/1

GET /megacorp/employee/1?pretty

GET /megacorp/employee/_search

GET /megacorp/employee/_search?q=last_name:Zhong

GET /megacorp/employee/_search
{
  "query": {
    "match": {
      "last_name": "Zhong"
    }
  }
}

GET /megacorp/employee/_search
{
  "query": {
    "filtered": {
      "filter": {
        "range": {
          "age": {
            "lt": 30
          }
        }
      },
      "query": {
        "match": {
          "last_name": "Zhong"
        }
      }
    }
  }
}

GET /megacorp/employee/_search
{
  "query": {
    "match": {
      "last_name": "Zhong"
    }
  },
  "highlight": {
    "fields": {
      "last_name": {}
    }
  }
}

GET /megacorp/employee/_search
{
  "aggs": {
    "all_interests": {
      "terms": {
        "field": "interests"
      }
    }
  }
}

GET /megacorp/employee/_search
{
  "query": {
    "match": {
      "last_name": "Zhong"
    }
  },
  "aggs": {
    "all_interests": {
      "terms": {
        "field": "interests"
      }
    }
  }
}

GET /megacorp/employee/_search
{
  "aggs": {
    "all_interests": {
      "terms": {
        "field": "interests"
      },
      "aggs": {
        "avg_age": {
          "avg": {
            "field": "age"
          }
        }
      }
    }
  }
}

GET /_cluster/health

PUT /blogs
{
  "settings": {
    "number_of_shards": 6,
    "number_of_replicas": 1
  }
}

PUT /blogs/_settings
{
  "number_of_replicas": 0
}

GET /megacorp/employee/_search?_source=age,interests

GET /megacorp/employee/1

GET /megacorp/employee/1/_source

PUT /website/blog/2?op_type=create
{
  "first_name": "Jay",
  "last_name": "Smith",
  "age": 27,
  "about": "I love rock music",
  "interests": [
    "sports",
    "music"
  ]
}

PUT /website/blog/122/_create
{
  "first_name": "Jay",
  "last_name": "Smith",
  "age": 27,
  "about": "I love rock music",
  "interests": [
    "sports",
    "music"
  ]
}

DELETE /website/blog/2

PUT /website/blog/2?version=13&version_type=external
{
  "title": "My first external blog entry",
  "text": "This is a piece of cake..."
}

GET /website/blog/2

POST /website/blog/2/_update
{
  "doc": {
    "tags": [
      "testing"
    ],
    "views": 0
  }
}

POST /_mget
{
  "docs": [
    {
      "_index": "website",
      "_type": "blog",
      "_id": 2
    },
    {
      "_index": "megacorp",
      "_type": "employee",
      "_id": 1,
      "_source": "age"
    }
  ]
}

POST /megacorp/employee/_mget
{
  "ids": [
    "2",
    "111"
  ]
}

POST /_bulk
{"delete":{"_index":"website","_type":"blog","_id":"223"}}
{"create":{"_index":"website","_type":"blog","_id":"223"}}
{"title":"My first blog post"}
{"index":{"_index":"website","_type":"blog"}}
{"title":"My second blog post"}
{"update":{"_index":"website","_type":"blog","_id":"223","_retry_on_conflict":3}}
{"doc":{"text":"My updated blog post"}}

POST /_bulk
{"create":{"_index":"website","_type":"blog","_id":"123"}}
{"title":"Cannot create - it already exists"}
{"index":{"_index":"website","_type":"blog","_id":"123"}}
{"title":"My first external blog entry","text":"This is a piece of cake..."}

POST /website/blog/_search

GET /megacorp/_search

GET /megacorp/employee/_mapping

GET /_analyze?analyzer=english
{
  "text": "Textes to analyze 5 32 遭受到"
}


GET megacorp/employee/_mapping

DELETE /megacorp2

PUT /megacorp2
{
  "mappings": {
    "employee": {
      "properties": {
        "about": {
          "type": "string",
          "analyzer": "english"
        },
        "age": {
          "type": "long"
        },
        "first_name": {
          "type": "string",
          "index": "not_analyzed"
        },
        "interests": {
          "type": "string"
        },
        "last_name": {
          "type": "string",
          "index": "no"
        }
      }
    }
  }
}


PUT /megacorp2/_mapping/employee
{
  "properties": {
    "about": {
      "type": "string",
      "analyzer": "english"
    },
    "age": {
      "type": "long"
    },
    "first_name": {
      "type": "string",
      "index": "not_analyzed"
    },
    "interests": {
      "type": "string"
    },
    "last_name": {
      "type": "string",
      "index": "no"
    }
  }
}

PUT /megacorp2/employee/1
{
  "first_name": "Jays 我",
  "last_name": "Smith",
  "age": 27,
  "about": "I love rock music 我饿么",
  "interests": [
    "sports",
    "music"
  ]
}

POST /megacorp2/employee
{
  "first_name": "Jays efe我",
  "last_name": "Smith",
  "age": 27,
  "about": "sfdf does you're I love rock music 我饿么",
  "interests": [
    "sports",
    "music"
  ]
}

PUT /megacorp/employee/66
{
  "first_name": [
    "sports",
    "music"
  ],
  "last_name": "Smith",
  "age": 27,
  "about": "I love rock music 我饿么",
  "interests": [
    "sports",
    "music"
  ]
}


GET /megacorp2/_search
{
  "query": {
    "match": {
      "last_name": "Smith"
    }
  }
}

POST megacorp/_search

PUT gb
{
  "tweet": {
    "properties": {
      "tweet": {
        "type": "string"
      },
      "user": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "gender": {
            "type": "string"
          },
          "age": {
            "type": "long"
          },
          "name": {
            "type": "object",
            "properties": {
              "full": {
                "type": "string"
              },
              "first": {
                "type": "string"
              },
              "last": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}


PUT gb/tweet/1
{
  "tweet": "Elasticsearch is very flexible",
  "user": {
    "id": "@johnsmith",
    "gender": "male",
    "age": 26,
    "name": {
      "full": "John Smith",
      "first": "John",
      "last": "Smith"
    }
  }
}

GET /gb/tweet/_search?pretty

GET /gb/tweet/_validate/query?explain
{
  "query": {
    "match": {
      "tweet": "really powerful"
    }
  }
}

GET /_search
{
  "query": {
    "filtered": {
      "query": {
        "match": {
          "email": "business opportunity"
        }
      },
      "filter": {
        "term": {
          "folder": "inbox"
        }
      }
    }
  }
}

GET /_search
{
  "query": {
    "filtered": {
      "filter": {
        "term": {
          "user_id": 1
        }
      }
    }
  },
  "sort": {
    "date": {
      "order": "desc"
    }
  }
}

GET gb/tweet/_search

GET gb/tweet/_search
{
  "query": {
    "filtered": {
      "query": {
        "match": {
          "tweet": "Elasticsearch is very flexible"
        }
      },
      "filter": {
        "term": {
          "user.id": "@johnsmith"
        }
      }
    }
  },
  "sort": [
    {
      "user.id": {
        "order": "desc"
      }
    },
    {
      "_score": {
        "order": "desc"
      }
    }
  ]
}

GET /gb/tweet/1/_explain
{
  "query": {
    "filtered": {
      "filter": {
        "term": {
          "user.id": "@johnsmith"
        }
      },
      "query": {
        "match": {
          "tweet": "Elasticsearch is very flexible"
        }
      }
    }
  }
}


GET /gb/tweet/1/_explain
{
  "query": {
    "filtered": {
      "filter": {
        "term": {
          "user.id": "@johnsmith"
        }
      },
      "query": {
        "match": {
          "tweet": "Elasticsearch"
        }
      }
    }
  }
}

GET /megacorp/_search?search_type=scan&scroll=1m
{
  "query": {
    "match_all": {}
  },
  "size": 1000
}


 

 

你可能感兴趣的:(es,dsl,elasticsearch,查询)