在elasticsearch中搜索URL?

时间:2018-07-27 13:38:53

标签: python elasticsearch elasticsearch-analyzers

我正在尝试使用弹性搜索来搜索URL,但是当我在URL中添加http://时,它不起作用。我正在使用UAX_URL_Email_Tokenizer作为令牌。我也尝试使用小写标记,但没有任何运气。我该如何解决?

映射代码:

{
  "mappings" : {
      "service" : {
          "properties" : {
              "title": { "type": "text", "fields": {"raw": {"type": "keyword"}}},
              "linked_items": {
                  "properties" : {
                      "name": {"type": "text", "fields": {"raw": {"type": "keyword"}}},
                      "additional_data": {"type": "text", "analyzer": "url_analyzer", "fields": {"raw": {"type": "keyword"}}}
                  }
              }
          }
      }
  },
  "settings" : {
      "analysis": {
        "filter" : {
          "stopwords_filter" : {
            "type" : "stop",
            "stopwords" : ["http", "https", "www"]
          }
        },
        "analyzer": {
          "url_analyzer": {
            "type": "custom",
            "tokenizer": "uax_url_email",
            "filter": [ "stopwords_filter", "lowercase" ]
          }
        }
      }
    }
}

搜索查询:

{
     "query": {
         "query_string": {
             "query": "*https://text.com*",
             "fields": ["title", "linked_items.additional_data"],
                          "default_operator": "AND"
         }
     },
     "size": 300
 }

0 个答案:

没有答案