Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb elasticsearch中索引时如何进行映射_Mongodb_Python 2.7_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Mongodb,Python 2.7,elasticsearch" /> elasticsearch,Mongodb,Python 2.7,elasticsearch" />

Mongodb elasticsearch中索引时如何进行映射

Mongodb elasticsearch中索引时如何进行映射,mongodb,python-2.7,elasticsearch,Mongodb,Python 2.7,elasticsearch,我在一个网站上使用了ElasticSearch,我从MongoDB索引数据 def postToEs(self): """ put data to the elasticsearch """ es = Elasticsearch() cursor = self.getMongoData() for document in cursor: esdoc={} esdoc["category"] = document.ge

我在一个网站上使用了
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)
        )

这很有效。但目前我必须在
状态
字段中搜索
弹性搜索
中的精确匹配。目前,如果我搜索纽约
的条目,它也会给出新罕布什尔州
的结果。我找到并看到了需要在数据上添加映射的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"
        }
    }
}
}'

删除现有河流配置索引

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"
        }
    }
}
}'
创建索引映射

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插件config sync mongodb放入elasticsearch


希望对你有帮助

1)我们可以向映射添加新字段。但我们不能在索引后修改映射。我们需要重新编制索引。请提供您当前的地图。。然后我会帮助你当前的映射是这样的:{code>{allnews:{properties:{category:{type:“string”},description:{type:“string”},link:{type:“string”},state:{type:“string”},title:{type:“string”}
我需要将
状态
映射为
“state:{type:“string”;“index:“not u analyed”}
如果我重新编制索引,我该如何指定映射。由于我是Elasticsearch新手,我对它的查询语法不太了解。谢谢你。实际上我已经用你在这里指定的方法解决了它。有没有办法从python脚本中实现这一点?