Field value factor with function query in nested object not found


(Silvestre Losada) #1

HI,

I have a nested object on my mappings with multiple values. Every user has a set of capacities each capacity has a number of points that describes the level of the user in that capacity.

{
	"userId": "1",
	"usertype": 2,
	"capacities": [{
		"name": "capacity1",
		"points": 200
	}, {
		"name": "capacity3",
		"points": 400
	}, {
		"name": "capacity2",
		"points": 100
	}]
},
{
	"userId": "2",
	"usertype": 2,
	"capacities": [{
		"name": "capacity1",
		"points": 200
	}, {
		"name": "capacity4",
		"points": 400
	}, {
		"name": "capacity2",
		"points": 100
	}]

}

I want to create a query that filter by user type and then rank the result using a set of capacities, I'm trying to use function score with field value factor.

I'm using a query like this, elasticsearch is not able to find the field capacities.point for field value factor.

{
    "query": {
		"function_score": {
			"functions": [{
				"filter": {
					"nested": {
						"filter": {
							"term": {
								"capacities.capacity": "capacity2"
							}
						},
						"path": "capacities"
					}
				},
				"field_value_factor": {
					"field": "capacities.point",
					"missing": 1
				}
			},
            {
    			"filter": {
					"nested": {
						"filter": {
							"term": {
								"capacities.capacity": "capacity1"
							}
						},
						"path": "capacities"
					}
				},
				"field_value_factor": {
					"field": "capacities.point",
					"missing": 1
				}
			}],
			"query": {
				"bool": {
					"should": [{
                        ... another query elements that influence on score
					}]
				}
			}
		}
	},
	"filter": {
		"bool": {
			"must": [{
				"terms": {
					"ustertype": [
						2
					]
				}
			}]
		}
	}
}

Kind regards.


(system) #2

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