# Rank feature field/query on nested field

**URL:** <https://discuss.elastic.co/t/rank-feature-field-query-on-nested-field/195359>\
**Category:** Elasticsearch\
**Created:** [August 15, 2019, 2:35pm UTC](https://discuss.elastic.co/t/rank-feature-field-query-on-nested-field/195359 "2019-08-15T14:35:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasoncodingguru](https://avatars.discourse-cdn.com/v4/letter/j/cdc98d/32.png) [@jasoncodingguru](https://discuss.elastic.co/u/jasoncodingguru)\
**Post date:** [August 15, 2019, 2:35pm UTC](https://discuss.elastic.co/t/rank-feature-field-query-on-nested-field/195359/1 "2019-08-15T14:35:42Z")

</div>

Hey guys,

I am trying to use the rank feature field/query on a nested object field.

The index is like below:  
{  
"id": {  
"type": "integer"  
},  
"sources": {  
"type": "nested",  
"properties": {  
"source": {  
"type": "text"  
}  
},  
"counter": {  
"type": "rank\_feature"  
}  
}  
}

one of the example document is  
{  
"id": 1,  
"page": "main",  
"sources" : [  
{  
"counter" : 1,  
"source" : "main"  
},  
{  
"counter" : 10,  
"source" : "browse"  
}  
}

Can someone please give some advise how to construct the query which can use the counter as rank feature field to boost?

---

<div class="post-metadata">

**Author:** ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)\
**Post date:** [August 24, 2019, 8:20pm UTC](https://discuss.elastic.co/t/rank-feature-field-query-on-nested-field/195359/2 "2019-08-24T20:20:12Z")

</div>

Hello! I am not sure I understand your mapping definition:

```auto
            "id": {
                "type": "integer"
            },
            "sources": {
                "type": "nested",
                "properties": {
                    "source": {
                        "type": "text"
                    }
                },
                "counter": {
                    "type": "rank_feature"
                }
            }

```

Did you intend to put counter under `sources` properties, like this:

```auto
           "id": {
                "type": "integer"
            },
            "sources": {
                "type": "nested",
                "properties": {
                    "source": {
                        "type": "text"
                    },
                    "counter": {
                        "type": "rank_feature"
                    }
                }
            }

```

There is also seems to be a mistake in the json of the doc for indexing that you provided.

About your question how to construct ranked feature query on a nested field, you do it similarly to any other nested query -- you nest it under `nested` keyword, like this:

```auto
{
    "query": {
		"nested" : {
			"path" : "sources",
			"query" : {
				"rank_feature": {
					"field" : "sources.counter"
				}
			}
		}
    }
}

```

For the boosting based on the rank\_feature query, you put in the `should` clause, as in the [example](https://www.elastic.co/guide/en/elasticsearch/reference/master/query-dsl-rank-feature-query.html#rank-feature-query-ex-query) in the documentation.

```auto
{
    "query": {
        "bool": {
            "must": {
                "match": {
                    "page": "main"
                }
            },
            "should": {
                "nested": {
                    "path": "sources",
                    "query": {
                        "rank_feature": {
                            "field": "sources.counter",
                            "boost" : 0.5
                        }
                    },
                    "score_mode": "max"
                }
            }
        }
    }
}

```

---

<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:** [September 21, 2019, 8:20pm UTC](https://discuss.elastic.co/t/rank-feature-field-query-on-nested-field/195359/3 "2019-09-21T20:20:14Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
