简体   繁体   中英

Elasticsearch and mongodb, partial search not working

This is my location Collection in mongodb:

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

I created one index using elastic Search:

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"]
                    }
                  } 
     }
  }
}

I created one mapping using elastic search:

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

}

Created river as follows:

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

If, I query GET /locations/_search?q=ABC , I get only one record (Full word search is happening, not happening for the partial word)

I almost spend a whole day on this but not able to solve this. Where am I going wrong?

I guess that it should be:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM