搜索不到ElasticSearch 5.2.2时带有特殊字符的URL

时间:2017-08-11 08:19:43

标签: elasticsearch

我无法搜索包含特殊字符的网址 http://example.sample.com/guide/Analyzers_Terms_and_Analysis_%28ABC%29_Guide

假设我已经索引了4个noteText

1)http://example.sample.com/guide/Analyzers_Terms_and_Analysis_%28ABC%29_Guide

2)example

3)Terms

4)Analysis

预期结果 - 当我使用完整网址选项(1)进行搜索时,它应该仅输出网址的确切结果,而不是使用其他索引值(例如exampleTerms,{{ 1}}。

搜索查询是 -

Analysis

我的映射是

{
  "query": {
    "bool": {
      "must": [
        {
          "constant_score": {
            "query": {
              "query_string": {
                "query": "http://example.sample.com/guide/Analyzers_Terms_and_Analysis_%28ABC%29_Guide",
                "fields": [
                  "noteText.ngrammed"
                ],
                "analyzer": "match_phrase_search"
              }
            },
            "boost": 5
          }
        },
        {
          "query_string": {
            "query": "http://example.sample.com/guide/Analyzers_Terms_and_Analysis_%28ABC%29_Guide",
            "fields": [
              "noteText.ngrammed"
            ]
          }
        }
      ]
    }
  }
}

索引设置 -

{
  "properties": {
    "userId": {
      "type": "long"
    },
    "noteText": {
      "analyzer": "match_phrase",
      "term_vector": "with_positions_offsets",
      "type": "text",
      "fields": {
        "ngrammed": {
          "term_vector": "with_positions_offsets",
          "type": "text"
        }
      }
    }
  }
}

1 个答案:

答案 0 :(得分:0)

更改了搜索查询以解决问题:

{{1}}