I work at a ecommerce company and we are rebuilding our search engine.
One of our queries is to discover what kind of category a given user query represents, like android should return smartphones category.
But we don't have a category android, but real users when search for android usually clicks on products of smartphones category, so we built a app to track this clicks and we index along the category the most hitted queries.
This is the mapping:
{
"category": {
"properties": {
"name": {
"type": "string",
"fields": {
}
},
"id": {
"type": "long"
},
"queries": {
"type": "nested",
"properties": {
"query": {
"type": "string",
"fields": {
}
},
"count": {
"type": "long"
}
}
}
}
}
}
And i index documents like this:
{
"id": 1,
"name": "Smartphones",
"queries": [
{
"query": "android",
"count": 100
},
{
"query": "iphone",
"count": 30
},
{
"query": "moto g",
"count": 20
}
]
}
And i want to query they by name and also by the user query (there is only the user query on this es query):
{
"_source": [
"name",
"queries"
],
"query": {
"function_score": {
"query": {
"nested": {
"path": "queries",
"query": {
"match": {
"queries.query": {
"query": "moto g",
"type": "phrase"
}
}
}
}
},
"functions": [
{
"script_score": {
"script": "_score * (doc['queries.count'].value * 1.0)"
}
}
],
"boost_mode": "replace",
"score_mode": "max"
}
}
}
The problem is, don't know why, but the queries.count seems to be always 0, i need to use nested inside the filter to get the actual document hitted?
Just want to query for moto g and return the smartphones category.
Also we are using Elasticsearch 2.4.4.