Sort search results based on query parameters

Hello,

I am trying to search for some keywords (eg java, hibernate, j2ee, jSP etc)
in two text fields [summary and description]. Since I need to get records
with any of the key words, I am using *BooleanQuery *
with should clause. And to search, I am using Multi-Match query. Below
is my query,

The query is working fine, but I want to get records with keyword java
first and then get records with other keywords. How can I achieve this?

{
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "java",
"fields": [
"summary",
"description"
],
"type": "phrase"
}
},
{
"multi_match": {
"query": "hibernate",
"fields": [
"summary",
"description"
],
"type": "phrase"
}
},
...........
]
}
}
}

Thanks

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/1661b6b3-c1f5-4500-83df-f145e994640e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

You mean that Java is a mandatory term?
In that case use a must clause instead of should.

David

Le 7 avr. 2015 à 08:03, ravi063@gmail.com a écrit :

Hello,

I am trying to search for some keywords (eg java, hibernate, j2ee, jSP etc) in two text fields [summary and description]. Since I need to get records with any of the key words, I am using BooleanQuery
with should clause. And to search, I am using Multi-Match query. Below is my query,

The query is working fine, but I want to get records with keyword java first and then get records with other keywords. How can I achieve this?

{
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "java",
"fields": [
"summary",
"description"
],
"type": "phrase"
}
},
{
"multi_match": {
"query": "hibernate",
"fields": [
"summary",
"description"
],
"type": "phrase"
}
},
...........
]
}
}
}

Thanks

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/1661b6b3-c1f5-4500-83df-f145e994640e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/5F8943FD-4CE5-4CA6-8DE6-1A60434A4B81%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.

Hi David,

Thanks for your reply. Java is not mandatory term. I want Elasticsearch to
return records having term Java first(if such records exists) followed by
records with other terms. Basically, I want to search for 2-3 keywords and
I should be able to sort results based on one of the search terms (java in
this case)

On Tuesday, April 7, 2015 at 12:17:01 PM UTC+5:30, David Pilato wrote:

You mean that Java is a mandatory term?
In that case use a must clause instead of should.

David

Le 7 avr. 2015 à 08:03, rav...@gmail.com <javascript:> a écrit :

Hello,

I am trying to search for some keywords (eg java, hibernate, j2ee, jSP
etc) in two text fields [summary and description]. Since I need to get
records with any of the key words, I am using *BooleanQuery *
with should clause. And to search, I am using Multi-Match query.
Below is my query,

The query is working fine, but I want to get records with keyword java
first and then get records with other keywords. How can I achieve this?

{
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "java",
"fields": [
"summary",
"description"
],
"type": "phrase"
}
},
{
"multi_match": {
"query": "hibernate",
"fields": [
"summary",
"description"
],
"type": "phrase"
}
},
...........
]
}
}
}

Thanks

--
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:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/1661b6b3-c1f5-4500-83df-f145e994640e%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/1661b6b3-c1f5-4500-83df-f145e994640e%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/4ffb97aa-dd75-4a15-8330-04f377bee503%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

I think you could wrap your query in a boosting query: Boosting Query | Elasticsearch Guide [1.5] | Elastic

Would this work?

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 7 avr. 2015 à 09:21, ravi063@gmail.com a écrit :

Hi David,

Thanks for your reply. Java is not mandatory term. I want Elasticsearch to return records having term Java first(if such records exists) followed by records with other terms. Basically, I want to search for 2-3 keywords and I should be able to sort results based on one of the search terms (java in this case)

On Tuesday, April 7, 2015 at 12:17:01 PM UTC+5:30, David Pilato wrote:
You mean that Java is a mandatory term?
In that case use a must clause instead of should.

David

Le 7 avr. 2015 à 08:03, rav...@gmail.com a écrit :

Hello,

I am trying to search for some keywords (eg java, hibernate, j2ee, jSP etc) in two text fields [summary and description]. Since I need to get records with any of the key words, I am using BooleanQuery
with should clause. And to search, I am using Multi-Match query. Below is my query,

The query is working fine, but I want to get records with keyword java first and then get records with other keywords. How can I achieve this?

{
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "java",
"fields": [
"summary",
"description"
],
"type": "phrase"
}
},
{
"multi_match": {
"query": "hibernate",
"fields": [
"summary",
"description"
],
"type": "phrase"
}
},
...........
]
}
}
}

Thanks

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/1661b6b3-c1f5-4500-83df-f145e994640e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/4ffb97aa-dd75-4a15-8330-04f377bee503%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/08CDDCAC-3AB5-4533-A067-912EE2D54410%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.

Hi David,

Based on your inputs I tried two options:

  1. Boosting Query: As suggested by you I used Boosting query and it
    worked like charm. But, search hit count remained same even after adding
    more and more terms. I am bit confused by this behavior (is my query right
    ?). Below is my modified query:
    {
    "query": {
    "boosting": {
    "positive": {
    "multi_match": {
    "query": "java",
    "fields": [
    "summary",
    "description"
    ],
    "type": "phrase"
    }
    },
    "negative": {
    "bool": {
    "should": [
    {
    "multi_match": {
    "query": "jsp",
    "fields": [
    "summary",
    "description"
    ],
    "type": "phrase"
    }
    },
    {
    "multi_match": {
    "query": "servlets",
    "fields": [
    "summary",
    "description"
    ],
    "type": "phrase"
    }
    }
    ]
    }
    },
    "negative_boost": 0.2
    }
    }
    }

  2. Added *boost *parameter: I added boost parameter to my old query and got
    good results. I included boost parameter to only one search term(java).

I added boost parameter to one of the

On Tuesday, April 7, 2015 at 12:58:37 PM UTC+5:30, David Pilato wrote:

I think you could wrap your query in a boosting query:
Boosting Query | Elasticsearch Guide [1.5] | Elastic

Would this work?

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 7 avr. 2015 à 09:21, rav...@gmail.com <javascript:> a écrit :

Hi David,

Thanks for your reply. Java is not mandatory term. I want Elasticsearch to
return records having term Java first(if such records exists) followed by
records with other terms. Basically, I want to search for 2-3 keywords and
I should be able to sort results based on one of the search terms (java in
this case)

On Tuesday, April 7, 2015 at 12:17:01 PM UTC+5:30, David Pilato wrote:

You mean that Java is a mandatory term?
In that case use a must clause instead of should.

David

Le 7 avr. 2015 à 08:03, rav...@gmail.com a écrit :

Hello,

I am trying to search for some keywords (eg java, hibernate, j2ee, jSP
etc) in two text fields [summary and description]. Since I need to get
records with any of the key words, I am using *BooleanQuery *
with should clause. And to search, I am using Multi-Match query.
Below is my query,

The query is working fine, but I want to get records with keyword java
first and then get records with other keywords. How can I achieve this?

{
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "java",
"fields": [
"summary",
"description"
],
"type": "phrase"
}
},
{
"multi_match": {
"query": "hibernate",
"fields": [
"summary",
"description"
],
"type": "phrase"
}
},
...........
]
}
}
}

Thanks

--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/1661b6b3-c1f5-4500-83df-f145e994640e%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/1661b6b3-c1f5-4500-83df-f145e994640e%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
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:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/4ffb97aa-dd75-4a15-8330-04f377bee503%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/4ffb97aa-dd75-4a15-8330-04f377bee503%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/b7aca4f4-24c3-4a5e-96de-c28db0c8894d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.