Elasticsearch发布荧光笔错误 - 无法突出显示

时间:2017-12-19 02:41:54

标签: elasticsearch lucene

尝试使用发布荧光笔进行搜索时出现以下错误:

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "field 'author_name' was indexed without offsets, cannot highlight"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query_fetch",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 1,
        "index": "post",
        "node": "abc",
        "reason": {
          "type": "illegal_argument_exception",
          "reason": "field 'author_name' was indexed without offsets, cannot highlight"
        }
      }
    ],
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "field 'author_name' was indexed without offsets, cannot highlight"
    }
  },
  "status": 400
}

这是我的映射:

{
    "post": {
        "mappings": {
            "page": {
                "_routing": {
                    "required": true
                },
                "properties": {
                    "author_name": {
                        "type": "text",
                        "store": true,
                        "index_options": "offsets",
                        "fields": {
                            "keyword": {
                                "type": "keyword"
                            }
                        },
                        "analyzer": "the_analyzer",
                        "search_analyzer": "the_search_analyzer"
                    },
                    "editor": {
                        "properties": {
                            "author_name": {
                                "type": "keyword"
                            }
                        }
                    }
                }
            },
            "blog_post": {
                "_routing": {
                    "required": true
                },
                "properties": {
                    "author_name": {
                        "type": "text",
                        "store": true,
                        "index_options": "offsets",
                        "fields": {
                            "keyword": {
                                "type": "keyword"
                            }
                        },
                        "analyzer": "the_analyzer",
                        "search_analyzer": "the_search_analyzer"
                    },
                    "editor": {
                        "properties": {
                            "author_name": {
                                "type": "keyword"
                            }
                        }
                    }
                }
            },
            "comments": {
                "_routing": {
                    "required": true
                },
                "_parent": {
                    "type": "blog_post"
                },
                "properties": {
                    "author_name": {
                        "type": "text",
                        "store": true,
                        "index_options": "offsets",
                        "fields": {
                            "keyword": {
                                "type": "keyword"
                            }
                        },
                        "analyzer": "the_analyzer",
                        "search_analyzer": "the_search_analyzer"
                    }
                }
            }
        }
    }
}

我的疑问:

GET post/article/_search?routing=cat
{
  "query": {
    "bool": {
      "filter": {
        "term": {
          "category": "cat"
        }
      },
      "must": [
        {
          "query_string": {
            "query": "bill",
            "fields": ["author_name"]
          }
        }]
    }
  },
  "highlight": {
    "fields": {
      "author_name": {}
    }
  }
}
  • Elasticsearch版本:5.1.1
  • Lucence版本:6.3.0

当我_update_by_query时,它会工作一段时间,然后再次失败(在添加更多数据之后)。

我做了一些谷歌搜索,并在Elasticsearch repo上发现了这个问题:

https://github.com/elastic/elasticsearch/issues/8558,cmiiw,基本上说我需要在同一个索引上对同一个字段名称使用相同的映射。但我已经这样做了,但我不知道editor对象是否有author_name可能导致该问题。

抛出该错误的Lucence代码:

https://github.com/apache/lucene-solr/blob/e2521b2a8baabdaf43b92192588f51e042d21e97/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/FieldOffsetStrategy.java#L92 https://github.com/apache/lucene-solr/blob/e2521b2a8baabdaf43b92192588f51e042d21e97/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/FieldHighlighter.java#L162

问题:如何修复此错误?感谢

0 个答案:

没有答案