如何按网址字段过滤结果

时间:2018-11-02 16:51:51

标签: elasticsearch

如何按URL字段过滤结果。例如,我有记录,其URL为http://abce.com/123/gth, http://abce.com/123/dsff, http://abce.com/123/dfsdf, http://abce.com/345/gth, http://abce.com/345/dfdh。我想将过滤器应用于http://abce.com/345/仅获取此域中的记录。我正在共享索引映射。在Kibana中,我可以通过url过滤结果,这将是通过curl的json。

索引映射:

 /testfilter2-index
{
    "settings": {
        "index": {
            "number_of_shards": 5,
            "number_of_replicas": 1,
            "refresh_interval": "60s",
            "analysis" : {
              "analyzer" : {
                "my_analyzer" : {
                    "tokenizer" : "standard",
                    "filter" : ["standard", "lowercase", "my_snow","asciifolding","english_stop"]
                }
              },
              "filter" : {
                "my_snow" : {
                    "type" : "snowball",
                    "language" : "Lovins"
                },
                "english_stop": {
          "type":        "stop",
          "stopwords":"_english_"
        }
            }
        }
        }
    },
    "mappings": {
        "doc": {
            "_source": {
                "enabled": true
            },
            "properties": {
                "content": {
                    "type": "text",
                    "index": "true",
                    "store": true,
                           "analyzer":"my_analyzer",
                            "search_analyzer": "my_analyzer"
                },
                "host": {
                    "type": "keyword",
                    "index": "true",
                    "store": true

                },
                "title": {
                    "type": "text",
                    "index": "true",
                    "store": true,
                            "analyzer":"my_analyzer",
                            "search_analyzer": "my_analyzer"

                },
                "url": {
                    "type": "keyword"


                }
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

由于您已将url映射为关键字,因此可以使用wildcard search功能

GET /testfilter2-index/_search
{
    "query": {
        "wildcard" : { 
            "url" : { 
                "value" : "http://abce.com/345/*", 
                "boost" : 2.0 
            } 
        }
    }
}