作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在网站中使用 ElasticSearch
,并从 MongoDB
索引数据。
def postToEs(self):
"""
put data to the elasticsearch
"""
es = Elasticsearch()
cursor = self.getMongoData()
for document in cursor:
esdoc={}
esdoc["category"] = document.get("category")
esdoc["description"] = document.get("description")
esdoc["title"] = document.get("title")
esdoc["link"] = document.get("link")
esdoc["state"] = document.get("state")
esdoc_id = esdoc["link"]
es.index(
index = 'news',
doc_type = 'allnews',
id = esdoc_id,
body = json.dumps(esdoc)
)
这效果很好。但目前我必须在 state
字段中搜索 elasticsearch
中的完全匹配项。目前,如果我搜索纽约
的条目,它也会给出新罕布什尔州
的结果。我找到了This link并看到elasticsearch文档,我需要在数据上添加映射
。我的问题是如何在当前场景中添加数据映射?或者有什么更好的方法吗?
最佳答案
删除现有索引
curl -XDELETE "http://hostname:9200/index/type"
删除现有河流配置索引
curl -XDELETE "http://hostname:9200/_river"
创建到索引的映射
curl -XPUT "http://hostname:9200/index/type/_mapping" -d'
{
"allnews": {
"properties": {
"category": {
"type": "string"
},
"description": {
"type": "string"
},
"link": {
"type": "string"
},
"state": {
"type": "string",
"index" : "not_analyzed"
},
"title": {
"type": "string"
}
}
}
}'
完成这些步骤后,将 River 插件配置同步 mongodb 到 Elasticsearch。
希望有帮助..!
关于mongodb - 如何在elasticsearch中索引时进行映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23238972/
我是一名优秀的程序员,十分优秀!