elasticsearch - Elasticsearch批量加载奇怪地丢失了3个文档中的1个

标签 elasticsearch elasticsearch-2.0

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

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

POST到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"
            }
        }
    }
}}

最佳答案

批量发布文档时,您需要确保在最后一行之后添加一个新行字符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

关于elasticsearch - Elasticsearch批量加载奇怪地丢失了3个文档中的1个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42396067/

相关文章:

hibernate - 日期范围查询不返回任何结果使用Elasticsearch进行 hibernate 搜索

elasticsearch - Elasticsearch中的条件更新: “Invalid op [none]”

elasticsearch - 使用NEST(.net)在Elasticsearch中进行复杂搜索

elasticsearch - 错误MergeMappingExcemption失败

elasticsearch - 如何优化Elasticsearch的全文搜索以匹配 'C++'之类的字符串

c# - 在Elasticsearch NEST中的主要多重匹配查询之后应用不同的过滤器

elasticsearch - Elasticsearch:如何获取字段的前10个不同值

elasticsearch - ElasticSearch功能评分查询

elasticsearch - Elasticsearch将嵌套字段与值数组匹配

scala - Elastic4s-为一个术语找到多个精确值