Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

当有新的 Blog 被保存时会触发 signals,在 ElasticSearch 中也生成一份并重建索引,最终在 Django 中实现高速查询

License

tmpbook/Django-with-ElasticSearch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

4 Commits

Repository files navigation

Django-with-ElasticSearch

当有新的 blog 被保存时触发一个 signals,在 ElasticSearch 中也生成一份并重建索引,最终在 Django 中实现高速查询 API: search

安装 ElasticSearch

mkdir elasticsearch-example
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.1.1.tar.gz
tar -xzf elasticsearch-5.1.1.tar.gz
./elasticsearch-5.1.1/bin/elasticsearch

安装运行 Django 项目

git clone https://github.com/tmpbook/Django-with-ElasticSearch.git
cd Django-with-ElasticSearch/elasticsearchproject
# 安装所需要的包
pip3 install -r requirements.txt
python manage.py runserver
# Starting development server at http://127.0.0.1:8000/
# 然后访问在这个 endpoint 添加一个 blog 对象
open http://127.0.0.1:8000/admin/elasticsearchapp/blogpost/add/

查看 ElasticSearch 并验证

curl -XGET 'localhost:9200/blogpost-index/blog_post_index/1?pretty'
# 应该是这样
{
 "_index" : "blogpost-index",
 "_type" : "blog_post_index",
 "_id" : "1",
 "_version" : 2,
 "found" : true,
 "_source" : {
 "author" : "admin",
 "posted_date" : "2017年12月21日",
 "text" : "Blog content.",
 "title" : "blog title"
 }
}

About me

知乎:临书

微信(WeChat):

谢谢阅读
Thanks for watching

About

当有新的 Blog 被保存时会触发 signals,在 ElasticSearch 中也生成一份并重建索引,最终在 Django 中实现高速查询

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /