【问题标题】:Elasticsearch: Need offset of exact matching stringElasticsearch:需要精确匹配字符串的偏移量
【发布时间】:2017-06-12 09:16:45
【问题描述】:

我有一个 html 文件,我需要找到完全匹配字符串的部分,比如“ANNUAL REPORT PURSUANT”。我正在使用最新版本的 Elasticsearch 5.4.0。我是弹性搜索的新手。对于索引,我将分析器定义如下:

{
    "index_name": {
        "settings": {
            "index": {
                "number_of_shards": "5",
                "provided_name": "index_name",
                "creation_date": "1496927173220",
                "analysis": {
                    "analyzer": {
                        "contact_section_analyzer": {
                            "tokenizer": "my_tokenizer"
                        }
                    },
                    "tokenizer": {
                        "my_tokenizer": {
                            "pattern": "(ANNUAL REPORT PURSUANT)",
                            "type": "pattern",
                            "group": "1"
                        }
                    }
                },
                "number_of_replicas": "1",
                "uuid": "vF3cAe-STJW-GrVxc7N8ww",
                "version": {
                    "created": "5040099"
                }
            }
        }
    }
}

现在我正在尝试使用如下分析来获得偏移量:

POST localhost:9200/sag_sec_items6/_analyze?pretty
{
  "analyzer": "contact_section_analyzer", 
  "text": "my_html_file_contents_already_indexed"
}

返回:

{
    "tokens": []
}

我检查了包含该文本的 html 文件。

使用带有单个 _id 的 _search 查询,我得到了整个 html 文件。 如何获取包含该文本的 偏移量或 html 标记

【问题讨论】:

    标签: elasticsearch analyzer elasticsearch-5


    【解决方案1】:

    我重新定义了我的分析仪设置如下:

    "settings": {
            "analysis": {
            "analyzer": {
            "contact_section_start_analyzer": {
                    "char_filter": "html_strip",
                    "tokenizer": "contact_section_start_tokenizer"
            }
            },
            "tokenizer": {
            "contact_section_start_tokenizer": {
                    "flags": "CASE_INSENSITIVE|DOTALL",
                    "pattern": "\\b(annual\\s+report\\s+pursuant)\\b",
                    "type": "pattern",
                    "group": "1"
            }
            }
            }
            }
    

    随着正则表达式模式的这种变化并在模式分析器中包含 CASE_INSENSITIVE|DOTALL 标志,我能够获得偏移量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-03
      • 2021-10-18
      • 1970-01-01
      相关资源
      最近更新 更多