I have a document under a type called "user". The user has different
attributes like this:
{
"id" : 3,
"location" : "New York",
"about_me" : "I like to surf, snowboard, and watch the Giants play.",
"interests" : {"extreme_sports" : "snowboard", "movies" : "inception"}
}
I want to search the user for data matching "snowboard", but only want to
look in the "interests" field. I've tried the following query:
{
"query" : {
"term" : {
"interests" : "snowboard"
}
}
}
I tried to restrict the search for the string "snowboard" to only the
"interests" field, however this returns no hits. I'm assuming it's because
the "interests" field contains a hash, not a simple string. How do I tell
elasticsearch to search for values within the "interests" field when it
contains a hash?
Yes, its because it contains a "hash", the fields indexed are actually
interests.extreme_sports, .. . So, you need to query on those. That said, I
think that in certain queries, we can support automatically expanding
something like interests field (which maps to an object mapping) to all its
sub fields.
I have a document under a type called "user". The user has different
attributes like this:
{
"id" : 3,
"location" : "New York",
"about_me" : "I like to surf, snowboard, and watch the Giants play.",
"interests" : {"extreme_sports" : "snowboard", "movies" : "inception"}
}
I want to search the user for data matching "snowboard", but only want to
look in the "interests" field. I've tried the following query:
{
"query" : {
"term" : {
"interests" : "snowboard"
}
}
}
I tried to restrict the search for the string "snowboard" to only the
"interests" field, however this returns no hits. I'm assuming it's because
the "interests" field contains a hash, not a simple string. How do I tell
elasticsearch to search for values within the "interests" field when it
contains a hash?
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.