Boosting a has_child in a bool query

Can you boost a has_child query inside of a bool query? Here is my example.
There are multiple has_child queries each of which represent a collection
that contains documents.

Mapping

curl -XPUT 'http://localhost:9200/collection-test?pretty=true' -d '{

"settings" : {
    "number_of_shards" : 1,
    "number_of_replicas" : 0
},
"mappings" : {

    "document": {
        "properties": {
            "bodyText": { "type": "string" }
        }
    },
 
    "collection_item": {
        "_parent": { "type": "document" },
        "_all" : {"enabled" : false},
        "properties": {                
            "collection_id": { "type": "integer", "index": 

"not_analyzed" }
}
}

}

}'

Documents

curl -XPUT 'http://localhost:9200/collection-test/document/1' -d '{

"bodyText" : "Creativity is inteligence having fun - Albert Einstein"

}'

curl -XPUT 'http://localhost:9200/collection-test/document/2' -d '{

"bodyText" : "Anything one man can imagine, other men can make real. - 

Jules Verne"
}'

curl -XPUT 'http://localhost:9200/collection-test/document/3' -d '{

"bodyText" : "Man will become better when you show him what he is like. 
  • Anton Chekhov"
    }'

Collections

curl -XPOST localhost:9200/collection-test/collection_item/1?parent=1 -d '{
"collection_id" : "1" }'

curl -XPOST localhost:9200/collection-test/collection_item/2?parent=1 -d '{
"collection_id" : "2" }'
curl -XPOST localhost:9200/collection-test/collection_item/4?parent=2 -d '{
"collection_id" : "2" }'

Multiple Term and Multiple Collection Query

Note: running this query requires at least ES 0.20.2 to support
"score_type".

curl -XPOST localhost:9200/collection-test/document/_search?pretty=true -d
'{
"query" : {
"bool" : {
"should" : [
{
"term" : { "bodyText" : { "value" : "inteligence", "boost"
: 1.0 } }
},
{
"term" : { "bodyText" : { "value" : "anything", "boost" :
1.0 }}
},
{
"has_child" : {
"type" : "collection_item",
"score_type" : "sum",
"query" : {
"term" : {
"collection_id" : "1"
}
}
}
},
{
"has_child" : {
"type" : "collection_item",
"score_type" : "sum",
"query" : {
"term" : {
"collection_id" : "2"
}
}
}
}
],
"minimum_number_should_match" : 1
}
}
}'

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Can you boost a has_child query inside of a bool query? Here is my
example. There are multiple has_child queries each of which represent
a collection that contains documents.

Yes, just write it as:

{ has_child: {
boost: 2,
...

clint

Mapping

curl -XPUT 'http://localhost:9200/collection-test?pretty=true' -d '{

"settings" : {
    "number_of_shards" : 1,
    "number_of_replicas" : 0
},
"mappings" : {

    "document": {
        "properties": {
            "bodyText": { "type": "string" }
        }
    },
 
    "collection_item": {
        "_parent": { "type": "document" },
        "_all" : {"enabled" : false},
        "properties": {                
            "collection_id": { "type": "integer", "index":

"not_analyzed" }
}
}

}

}'

Documents

curl -XPUT 'http://localhost:9200/collection-test/document/1' -d '{

"bodyText" : "Creativity is inteligence having fun - Albert

Einstein"
}'

curl -XPUT 'http://localhost:9200/collection-test/document/2' -d '{

"bodyText" : "Anything one man can imagine, other men can make

real. - Jules Verne"
}'

curl -XPUT 'http://localhost:9200/collection-test/document/3' -d '{

"bodyText" : "Man will become better when you show him what he is

like. - Anton Chekhov"
}'

Collections

curl -XPOST localhost:9200/collection-test/collection_item/1?parent=1
-d '{ "collection_id" : "1" }'

curl -XPOST localhost:9200/collection-test/collection_item/2?parent=1
-d '{ "collection_id" : "2" }'
curl -XPOST localhost:9200/collection-test/collection_item/4?parent=2
-d '{ "collection_id" : "2" }'

Multiple Term and Multiple Collection Query

Note: running this query requires at least ES 0.20.2 to support
"score_type".

curl -XPOST
localhost:9200/collection-test/document/_search?pretty=true -d '{
"query" : {
"bool" : {
"should" : [
{
"term" : { "bodyText" : { "value" : "inteligence",
"boost" : 1.0 } }
},
{
"term" : { "bodyText" : { "value" : "anything",
"boost" : 1.0 }}
},
{
"has_child" : {
"type" : "collection_item",
"score_type" : "sum",
"query" : {
"term" : {
"collection_id" : "1"
}
}
}
},
{
"has_child" : {
"type" : "collection_item",
"score_type" : "sum",
"query" : {
"term" : {
"collection_id" : "2"
}
}
}
}
],
"minimum_number_should_match" : 1
}
}
}'

--
You received this message because you are subscribed to the Google
Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Many thanks. Adding a boost field works. You are the only one here
answering my questions so far :slight_smile: . The documentation for has_child doesn't
show a boost field. Is there a process for updating it?
(http://www.elasticsearch.org/guide/reference/query-dsl/has-child-filter.html)

On Tuesday, 12 February 2013 05:41:38 UTC-6, Clinton Gormley wrote:

Can you boost a has_child query inside of a bool query? Here is my
example. There are multiple has_child queries each of which represent
a collection that contains documents.

Yes, just write it as:

{ has_child: {
boost: 2,
...

clint

Mapping

curl -XPUT 'http://localhost:9200/collection-test?pretty=true' -d '{

"settings" : { 
    "number_of_shards" : 1, 
    "number_of_replicas" : 0 
}, 
"mappings" : { 

    "document": { 
        "properties": { 
            "bodyText": { "type": "string" } 
        } 
    }, 
  
    "collection_item": { 
        "_parent": { "type": "document" }, 
        "_all" : {"enabled" : false}, 
        "properties": {                 
            "collection_id": { "type": "integer", "index": 

"not_analyzed" }
}
}

} 

}'

Documents

curl -XPUT 'http://localhost:9200/collection-test/document/1' -d '{

"bodyText" : "Creativity is inteligence having fun - Albert 

Einstein"
}'

curl -XPUT 'http://localhost:9200/collection-test/document/2' -d '{

"bodyText" : "Anything one man can imagine, other men can make 

real. - Jules Verne"
}'

curl -XPUT 'http://localhost:9200/collection-test/document/3' -d '{

"bodyText" : "Man will become better when you show him what he is 

like. - Anton Chekhov"
}'

Collections

curl -XPOST localhost:9200/collection-test/collection_item/1?parent=1
-d '{ "collection_id" : "1" }'

curl -XPOST localhost:9200/collection-test/collection_item/2?parent=1
-d '{ "collection_id" : "2" }'
curl -XPOST localhost:9200/collection-test/collection_item/4?parent=2
-d '{ "collection_id" : "2" }'

Multiple Term and Multiple Collection Query

Note: running this query requires at least ES 0.20.2 to support
"score_type".

curl -XPOST
localhost:9200/collection-test/document/_search?pretty=true -d '{
"query" : {
"bool" : {
"should" : [
{
"term" : { "bodyText" : { "value" : "inteligence",
"boost" : 1.0 } }
},
{
"term" : { "bodyText" : { "value" : "anything",
"boost" : 1.0 }}
},
{
"has_child" : {
"type" : "collection_item",
"score_type" : "sum",
"query" : {
"term" : {
"collection_id" : "1"
}
}
}
},
{
"has_child" : {
"type" : "collection_item",
"score_type" : "sum",
"query" : {
"term" : {
"collection_id" : "2"
}
}
}
}
],
"minimum_number_should_match" : 1
}
}
}'

--
You received this message because you are subscribed to the Google
Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

On Tue, 2013-02-12 at 14:17 -0800, David Hagar wrote:

Many thanks. Adding a boost field works. You are the only one here
answering my questions so far :slight_smile: . The documentation for has_child
doesn't show a boost field. Is there a process for updating it?
(http://www.elasticsearch.org/guide/reference/query-dsl/has-child-filter.html)

You can fork the docs at
https://github.com/elasticsearch/elasticsearch.github.com and send a
pull request

thanks

clint

On Tuesday, 12 February 2013 05:41:38 UTC-6, Clinton Gormley wrote:

    > 
    > Can you boost a has_child query inside of a bool query? Here
    is my 
    > example. There are multiple has_child queries each of which
    represent 
    > a collection that contains documents. 
    
    Yes, just write it as: 
    
      { has_child: { 
           boost: 2, 
           ... 
    
    clint 
    
    > 
    > 
    > 
    > 
    > Mapping 
    > 
    > 
    > curl -XPUT
    'http://localhost:9200/collection-test?pretty=true' -d '{ 
    > 
    > 
    >     "settings" : { 
    >         "number_of_shards" : 1, 
    >         "number_of_replicas" : 0 
    >     }, 
    >     "mappings" : { 
    >     
    >         "document": { 
    >             "properties": { 
    >                 "bodyText": { "type": "string" } 
    >             } 
    >         }, 
    >       
    >         "collection_item": { 
    >             "_parent": { "type": "document" }, 
    >             "_all" : {"enabled" : false}, 
    >             "properties": {                 
    >                 "collection_id": { "type": "integer",
    "index": 
    > "not_analyzed" } 
    >             } 
    >         } 
    >           
    >     } 
    > }' 
    > 
    > 
    > 
    > 
    > Documents 
    > 
    > 
    > curl -XPUT
    'http://localhost:9200/collection-test/document/1' -d '{ 
    > 
    > 
    >     "bodyText" : "Creativity is inteligence having fun -
    Albert 
    > Einstein" 
    > }' 
    > 
    > 
    > curl -XPUT
    'http://localhost:9200/collection-test/document/2' -d '{ 
    >     
    >     "bodyText" : "Anything one man can imagine, other men
    can make 
    > real. - Jules Verne" 
    > }' 
    > 
    > 
    > curl -XPUT
    'http://localhost:9200/collection-test/document/3' -d '{ 
    >     
    >     "bodyText" : "Man will become better when you show him
    what he is 
    > like. - Anton Chekhov" 
    > }' 
    > 
    > 
    > 
    > 
    > 
    > 
    > 
    > 
    > Collections 
    > 
    > 
    > curl -XPOST
    localhost:9200/collection-test/collection_item/1?parent=1 
    > -d '{ "collection_id" : "1" }' 
    > 
    > 
    > curl -XPOST
    localhost:9200/collection-test/collection_item/2?parent=1 
    > -d '{ "collection_id" : "2" }' 
    > curl -XPOST
    localhost:9200/collection-test/collection_item/4?parent=2 
    > -d '{ "collection_id" : "2" }' 
    > 
    > 
    > 
    > 
    > 
    > 
    > Multiple Term and Multiple Collection Query 
    > 
    > 
    > Note: running this query requires at least ES 0.20.2 to
    support 
    > "score_type". 
    > 
    > 
    > 
    > 
    > curl -XPOST 
    > localhost:9200/collection-test/document/_search?pretty=true
    -d '{ 
    > "query" : { 
    >     "bool" : {       
    >         "should" : [ 
    >             { 
    >                 "term" : { "bodyText" : { "value" :
    "inteligence", 
    > "boost" : 1.0 } } 
    >             }, 
    >             { 
    >                 "term" : { "bodyText" : { "value" :
    "anything", 
    > "boost" : 1.0 }} 
    >             }, 
    >             { 
    >                 "has_child" : {       
    >                     "type" : "collection_item", 
    >                     "score_type" : "sum", 
    >                     "query" : { 
    >                         "term" : { 
    >                             "collection_id" : "1" 
    >                         } 
    >                     } 
    >                 } 
    >             }, 
    >             { 
    >                 "has_child" : {       
    >                     "type" : "collection_item", 
    >                     "score_type" : "sum", 
    >                     "query" : { 
    >                         "term" : { 
    >                             "collection_id" : "2" 
    >                         } 
    >                     } 
    >                 } 
    >             } 
    >         ], 
    >         "minimum_number_should_match" : 1 
    >     } 
    >     } 
    > }' 
    > 
    > 
    > -- 
    > You received this message because you are subscribed to the
    Google 
    > Groups "elasticsearch" group. 
    > To unsubscribe from this group and stop receiving emails
    from it, send 
    > an email to elasticsearc...@googlegroups.com. 
    > For more options, visit
    https://groups.google.com/groups/opt_out. 
    >   
    >   

--
You received this message because you are subscribed to the Google
Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

FYI, every query type supports a boost. Also, I have completely
documented every query, filter, and facet while implementing
Elastic.js. These docs can be useful even when using the RESP api,
especially if you use them along with the query translator that
converts the javascript to the REST version of the request.

http://docs.fullscale.co/elasticjs/
http://docs.fullscale.co/translator/

Thanks,
Matt Weber

On Wed, Feb 13, 2013 at 1:48 AM, Clinton Gormley clint@traveljury.com wrote:

On Tue, 2013-02-12 at 14:17 -0800, David Hagar wrote:

Many thanks. Adding a boost field works. You are the only one here
answering my questions so far :slight_smile: . The documentation for has_child
doesn't show a boost field. Is there a process for updating it?
(Elasticsearch Platform — Find real-time answers at scale | Elastic)

You can fork the docs at
https://github.com/elasticsearch/elasticsearch.github.com and send a
pull request

thanks

clint

On Tuesday, 12 February 2013 05:41:38 UTC-6, Clinton Gormley wrote:

    >
    > Can you boost a has_child query inside of a bool query? Here
    is my
    > example. There are multiple has_child queries each of which
    represent
    > a collection that contains documents.

    Yes, just write it as:

      { has_child: {
           boost: 2,
           ...

    clint

    >
    >
    >
    >
    > Mapping
    >
    >
    > curl -XPUT
    'http://localhost:9200/collection-test?pretty=true' -d '{
    >
    >
    >     "settings" : {
    >         "number_of_shards" : 1,
    >         "number_of_replicas" : 0
    >     },
    >     "mappings" : {
    >
    >         "document": {
    >             "properties": {
    >                 "bodyText": { "type": "string" }
    >             }
    >         },
    >
    >         "collection_item": {
    >             "_parent": { "type": "document" },
    >             "_all" : {"enabled" : false},
    >             "properties": {
    >                 "collection_id": { "type": "integer",
    "index":
    > "not_analyzed" }
    >             }
    >         }
    >
    >     }
    > }'
    >
    >
    >
    >
    > Documents
    >
    >
    > curl -XPUT
    'http://localhost:9200/collection-test/document/1' -d '{
    >
    >
    >     "bodyText" : "Creativity is inteligence having fun -
    Albert
    > Einstein"
    > }'
    >
    >
    > curl -XPUT
    'http://localhost:9200/collection-test/document/2' -d '{
    >
    >     "bodyText" : "Anything one man can imagine, other men
    can make
    > real. - Jules Verne"
    > }'
    >
    >
    > curl -XPUT
    'http://localhost:9200/collection-test/document/3' -d '{
    >
    >     "bodyText" : "Man will become better when you show him
    what he is
    > like. - Anton Chekhov"
    > }'
    >
    >
    >
    >
    >
    >
    >
    >
    > Collections
    >
    >
    > curl -XPOST
    localhost:9200/collection-test/collection_item/1?parent=1
    > -d '{ "collection_id" : "1" }'
    >
    >
    > curl -XPOST
    localhost:9200/collection-test/collection_item/2?parent=1
    > -d '{ "collection_id" : "2" }'
    > curl -XPOST
    localhost:9200/collection-test/collection_item/4?parent=2
    > -d '{ "collection_id" : "2" }'
    >
    >
    >
    >
    >
    >
    > Multiple Term and Multiple Collection Query
    >
    >
    > Note: running this query requires at least ES 0.20.2 to
    support
    > "score_type".
    >
    >
    >
    >
    > curl -XPOST
    > localhost:9200/collection-test/document/_search?pretty=true
    -d '{
    > "query" : {
    >     "bool" : {
    >         "should" : [
    >             {
    >                 "term" : { "bodyText" : { "value" :
    "inteligence",
    > "boost" : 1.0 } }
    >             },
    >             {
    >                 "term" : { "bodyText" : { "value" :
    "anything",
    > "boost" : 1.0 }}
    >             },
    >             {
    >                 "has_child" : {
    >                     "type" : "collection_item",
    >                     "score_type" : "sum",
    >                     "query" : {
    >                         "term" : {
    >                             "collection_id" : "1"
    >                         }
    >                     }
    >                 }
    >             },
    >             {
    >                 "has_child" : {
    >                     "type" : "collection_item",
    >                     "score_type" : "sum",
    >                     "query" : {
    >                         "term" : {
    >                             "collection_id" : "2"
    >                         }
    >                     }
    >                 }
    >             }
    >         ],
    >         "minimum_number_should_match" : 1
    >     }
    >     }
    > }'
    >
    >
    > --
    > You received this message because you are subscribed to the
    Google
    > Groups "elasticsearch" group.
    > To unsubscribe from this group and stop receiving emails
    from it, send
    > an email to elasticsearc...@googlegroups.com.
    > For more options, visit
    https://groups.google.com/groups/opt_out.
    >
    >

--
You received this message because you are subscribed to the Google
Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.