ElasticSearch edge-ngram无法正常工作

时间:2014-08-27 13:52:39

标签: java sql elasticsearch elasticsearch-jdbc-river

我已使用以下设置配置my index,并且matchAll查询结果在IPRANGE字段中具有值“trial”。

设置:

{
        "settings" : {
            "analysis": {
                "filter": {
                    "autocomplete_filter": { 
                        "type":     "edge_ngram",
                        "min_gram": 1,
                        "max_gram": 5
                    }
                },
                "analyzer": {
                    "autocomplete": {
                        "type":      "custom",
                        "tokenizer": "standard",
                        "filter": [
                            "lowercase",
                            "autocomplete_filter" 
                        ]
                    }
                }
            }
        },
            "mappings" : {
               "users" : {
                   "properties" : {
                       "IPRANGE" : {
                           "type" : "string",
                           "analyzer" : "autocomplete"
                       }
                   }
               }
            },
               refresh_interval: "1000"
    }

但是当我使用以下有效载荷进行搜索时,它不会返回结果,即0次点击。

URL:

http://xxxxxx:9200/db2/users/_search

有效载荷:

{

  "query": {

  "match": {

     "IPRANGE": "tr"

  }

  }

}

可能是什么问题?

1 个答案:

答案 0 :(得分:1)

您是如何索引文档的?这是一个有效的例子:

我更改了映射,以便autocomplete分析器用于索引IPRANGE字段,在搜索字段时将使用默认分析器(您不希望拆分搜索词以同样的方式)。

/POST http://localhost:9200/test
{
    "settings": {
        "analysis": {
            "filter": {
                "autocomplete_filter": {
                    "type": "edge_ngram",
                    "min_gram": 1,
                    "max_gram": 5
                }
            },
            "analyzer": {
                "autocomplete": {
                    "type": "custom",
                    "tokenizer": "standard",
                    "filter": [
                        "lowercase",
                        "autocomplete_filter"
                    ]
                }
            }
        }
    },
    "mappings": {
        "users": {
            "properties": {
                "IPRANGE": {
                    "type": "string",
                    "search_analyzer": "autocomplete"
                }
            }
        }
    }
}

索引文件

/POST http://localhost:9200/test/users/1/
{
   "IPRANGE":"trial"
}

搜索请求:

/POST http://localhost:9200/test/users/_search
{
  "query": {
    "match": {
      "IPRANGE": "tr"
    }
  }
}

返回以下结果:

{
    took: 10
    timed_out: false
    _shards: {
        total: 5
        successful: 5
         failed: 0
    }
    hits: {
        total: 1
        max_score: 0.30685282
        hits: [
            {
                _index: test
                _type: users
                _id: 1
                _score: 0.30685282
                _source: {
                    IPRANGE: trial
                }
            }
        ]
    }
}