【问题标题】:Elasticseach bulk load strangely missing 1 of 3 documentsElasticsearch 批量加载奇怪地缺少 3 个文档中的 1 个
【发布时间】:2017-07-12 18:32:30
【问题描述】:

https://www.elastic.co/guide/en/elasticsearch/guide/current/shingles.html 的带状疱疹示例之后,我遇到了奇怪的问题

当我尝试索引该教程中的三个文档时,只有其中两个被索引,ID 为 3 的文档永远不会被索引。

发送到http://elastic:9200/myIndex/page/_bulk 的请求是:

{ "index": { "_id": 1 }}
{ "text": "Sue ate the alligator" }
{ "index": { "_id": 2 }}
{ "text": "The alligator ate Sue" }
{ "index": { "_id": 3 }}
{ "text": "Sue never goes anywhere without her alligator skin purse" }

但反应是:

{
"took": 18,
"errors": false,
"items": [
    {
        "index": {
            "_index": "myIndex",
            "_type": "page",
            "_id": "1",
            "_version": 1,
            "_shards": {
                "total": 1,
                "successful": 1,
                "failed": 0
            },
            "status": 201
        }
    },
    {
        "index": {
            "_index": "myIndex",
            "_type": "page",
            "_id": "2",
            "_version": 1,
            "_shards": {
                "total": 1,
                "successful": 1,
                "failed": 0
            },
            "status": 201
        }
    }
]}

索引和映射定义:

{
"settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0,
    "analysis": {
        "filter": {
            "filter_shingle": {
                "type": "shingle",
                "max_shingle_size": 5,
                "min_shingle_size": 2,
                "output_unigrams": "false"
            },
            "filter_stop": {
                "type": "stop"
            }
        },
        "analyzer": {
            "analyzer_shingle": {
                "tokenizer": "standard",
                "filter": ["standard", "lowercase", "filter_stop", "filter_shingle"]
            }
        }
    }
},
"mappings": {
    "page": {
        "properties": {
            "text": {
                "type": "string",
                "index_options": "offsets",
                "analyzer": "standard",
                "fields": {
                    "shingles": {
                        "search_analyzer": "analyzer_shingle",
                        "analyzer": "analyzer_shingle",
                        "type": "string"
                    }
                }
            },
            "title": {
                "type": "string",
                "index_options": "offsets",
                "analyzer": "standard",
                "search_analyzer": "standard"
            }
        }
    }
}}

【问题讨论】:

  • 您确定在最后一个文档之后包含换行符吗?
  • 解决了,这是一个基本错误,您能否将其发布为答案,以便我可以信任您?谢谢。

标签: elasticsearch elasticsearch-2.0


【解决方案1】:

批量发布文档时,需要确保在最后一行之后包含一个换行符explained in the official docs

curl -XPOST http://elastic:9200/myIndex/page/_bulk -d '
{ "index": { "_id": 1 }}
{ "text": "Sue ate the alligator" }
{ "index": { "_id": 2 }}
{ "text": "The alligator ate Sue" }
{ "index": { "_id": 3 }}
{ "text": "Sue never goes anywhere without her alligator skin purse" }
'      <--- new line

【讨论】:

    猜你喜欢
    • 2014-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-18
    • 2019-11-30
    相关资源
    最近更新 更多