2013-10-30 43 views
0

部分搜索这是我的位置集合中的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

我想这应该是:

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

由于一吨!它的工作现在很好。使用的查询:GET/bwitter/_search?q = ABC –