Elasticsearch和mongodb,部分搜索不起作用

时间:2013-10-30 11:36:21

标签: java mongodb elasticsearch

这是我在mongodb的位置收藏:

{ "_id" : ObjectId("5270d36f28f31fd8fa016441"), "stateName" : "A5", "cityName" : "ABCNEW2" }
{ "_id" : ObjectId("5270d37328f31fd8fa016442"), "stateName" : "A5", "cityName" : "ABC" }
{ "_id" : ObjectId("5270d37b28f31fd8fa016443"), "stateName" : "65", "cityName" : "ABCRW" }

我使用弹性搜索创建了一个索引:

POST /bwitter
{"index": 
  { "number_of_shards": 1,
    "analysis": {
       "filter": {
                  "mynGram" : {"type": "nGram", "min_gram": 2, "max_gram": 10}
                 },
       "analyzer": { "a1" : {
                    "type":"custom",
                    "tokenizer": "standard",
                    "filter": ["lowercase", "mynGram"]
                    }
                  } 
     }
  }
}

我使用弹性搜索创建了一个映射:

PUT /bwitter/bweet/_mapping
{
    "bweet" : {
        "index_analyzer" : "a1",
        "search_analyzer" : "standard", 
        "properties" : {
            "stateName": {"type":"string", "analyzer":"standard"},
            "cityName" : {"type" : "string" }
        }
    }

}

创建河流如下:

PUT /_river/mongodb/_meta
{ 
    "type": "mongodb", 
    "mongodb": { 
        "db": "rakeshdb", 
        "collection": "locations"
    }, 
    "index": {
        "name": "locations", 
        "type": "bweet" 
    }
}

如果,我查询GET /locations/_search?q=ABC,我只获得一条记录(全字搜索正在发生,而不是部分字发生)

我差不多花了一整天的时间但却无法解决这个问题。我哪里错了?

1 个答案:

答案 0 :(得分:1)

我想它应该是:

PUT /_river/mongodb/_meta
{ 
    "type": "mongodb", 
    "mongodb": { 
        "db": "rakeshdb", 
        "collection": "locations"
    }, 
    "index": {
        "name": "bwitter", 
        "type": "bweet" 
    }
}