# Mongodb index parent field?

**URL:** <https://discuss.elastic.co/t/mongodb-index-parent-field/13099>\
**Category:** Elasticsearch\
**Created:** [August 7, 2013, 5:08am UTC](https://discuss.elastic.co/t/mongodb-index-parent-field/13099 "2013-08-07T05:08:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![manhnv](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@manhnv](https://discuss.elastic.co/u/manhnv)\
**Post date:** [August 7, 2013, 5:08am UTC](https://discuss.elastic.co/t/mongodb-index-parent-field/13099/1 "2013-08-07T05:08:04Z")

</div>

Hi everybody!

I have collection users, all document have structure like following:

{  
"username": "manhnv",  
"userId": 123456,  
"followers":[  
{  
"userId":123,  
"username": "datmoi",  
},  
{  
"userId": 456,  
"username": "hoangpheo",  
}  
}

And more documents:  
{  
"username": "hungga",  
"userId": 123456,  
"followers":[  
{  
"userId": 456,  
"username": "manhnv",  
}  
}

I want to index "username" field (parent, not in followers). I do like  
following:

curl -XPUT [http://localhost:9200/users](http://localhost:9200/users) -d '  
{  
"mappings":{  
"multisearch":{  
"properties":{  
"username":{  
"type":"string",  
"analyzer":"partial\_name",  
"search\_analyzer":"partial\_name",  
"index\_analyzer":"partial\_name"  
}  
}  
}  
},  
"settings":{  
"analysis":{  
"filter":{  
"name\_ngrams":{  
"side":"front",  
"max\_gram":20,  
"min\_gram":2,  
"type":"NGram"  
}  
},  
"analyzer":{  
"full\_name":{  
"filter":[  
"standard",  
"lowercase",  
"asciifolding"  
],  
"type":"custom",  
"tokenizer":"standard"  
},  
"partial\_name":{  
"filter":[  
"standard",  
"lowercase",  
"asciifolding",  
"name\_ngrams"  
],  
"type":"custom",  
"tokenizer":"standard"  
}  
}  
}  
}  
}  
'

And I add new mongodb river to elasticsearch:  
curl -XPUT 'localhost:9200/\_river/mongodb/\_meta' -d '{  
"type": "mongodb",  
"mongodb": {  
"servers": [  
{"host": "Konoha", "port": 27018},  
{"host": "Konoha", "port": 27027}  
],  
"db": "mydatabase",  
"collection": "users",  
"options": {  
"secondary\_read\_preference": true,  
"drop\_collection": true  
},  
"gridfs": false  
},  
"index": {  
"name": "users",  
"type": "multisearch"  
}  
}'

And now I try to search with keyword "manh", I run in browser:  
[http://localhost:9200/users/multisearch/\_search?pretty=true&q=username:manh](http://localhost:9200/users/multisearch/_search?pretty=true&q=username:manh)

The results are two documents that I describe above. I think ElasticSearch  
also indexs field username in followers field?

I want only row have username=manhnv (parent)

Can you help me index only parent field username?

Thanks for your helping 🙂

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:22am UTC](https://discuss.elastic.co/t/mongodb-index-parent-field/13099/2 "2017-07-06T02:22:32Z")

</div>

Closed on July 6, 2017, 2:22am UTC


