Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to find a field mapper for field in nested query using field_value_factor #12871

Closed
vrepsys opened this issue Aug 14, 2015 · 4 comments
Closed

Comments

@vrepsys
Copy link

vrepsys commented Aug 14, 2015

Here's the mapping:

PUT books-index
{
  "mappings": {
    "books": {
      "properties": {
        "tags": {
          "type": "nested",
          "fields": {
            "name": {
              "type": "string"
            },
            "weight": {
              "type": "float"
            }
          }
        }
      }
    }
  }
}

Then doing a nested query using a field_value_factor fails with an error

GET books-index/books/_search
{
  "query": {
    "nested": {
      "path": "tags",
      "score_mode": "sum",
      "query": {
        "function_score": {
          "query": {
            "match": {
              "tags.name": "world"
            }
          },
        "field_value_factor": {
            "field": "weight"
         }
        }
      }
    }
  }
}

The error: "nested: ElasticsearchException[Unable to find a field mapper for field [weight]]"

Interestingly, if there's one book in the index with tags - there's no error and the query works well.

Why is this happening? how can I prevent the error when there are no books with tags in the index?

Any ideas?

Thank you!

@jpountz
Copy link
Contributor

jpountz commented Aug 14, 2015

I suspect this is because you gave weight instead of tags.weight as a field name. For such questions however, please use the forums instead of creating a Github issue. We aim at using Github issues only for confirmed bugs and feature requests.

@jpountz jpountz closed this as completed Aug 14, 2015
@vrepsys
Copy link
Author

vrepsys commented Aug 14, 2015

There's a related question on stackoverflow since a long time ago that gets upvotes, but nobody can answer: http://stackoverflow.com/questions/27274240/function-score-query-with-field-value-factor-on-not-yet-existing-field

Also the issue very similar to this: #10948
But it is not clear if and how it's been resolved.

Are you sure this is not an issue with elastic?

P.S. "tags.weight" instead of "tags" makes no difference.

@clintongormley
Copy link

@vrepsys your mapping is incorrect. You used fields instead of properties.

PUT books-index
{
  "mappings": {
    "books": {
      "properties": {
        "tags": {
          "type": "nested",
          "properties": {
            "name": {
              "type": "string"
            },
            "weight": {
              "type": "float"
            }
          }
        }
      }
    }
  }
}

At least in 2.0 (not sure about before), your mapping fails with an exception

@vrepsys
Copy link
Author

vrepsys commented Aug 15, 2015

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants