I have elasticsearch query like ;
{
"query": {
"bool": {
"must": [{
"match": {
"text": {
"query": "yayla kent sitesi",
"fuzziness": "2"
}
}
},
{
"match": {
"type": {
"query": "2"
}
}
}
]
}
}
}
and there is records
"text":"yaylakent sitesi"
but I can't get results using fuzzy search its return many unrelated documents. Can someone help me to have a query which have one or few space sensitive search in field.
"query": "yayla kent sitesi"
should not combine to,
"query": "yaylakent sitesi"
Related
I want to find names that start or have the phrase man in them. But I also want to query on different indexes.
So it should return all fields that have the term man in them such as hoffman last name, or anything that has the term in it.
How can I achieve this?
"query": {
"multi_match": {
"query": "man",
"fields": [
"name",
"last_name",
"email"
]
}
}
}
{
"query": {
"multi_match": {
"query": "man",
"fields": [
"billing.name",
"billing.last_name",
"billing.email"
]
}
}
}
If you want to search across multiple indexes, then you can use _index field, and for searching across multiple fields you can use query_String instead of a multi-match query.
GET /_search
{
"query": {
"bool": {
"must": [
{
"terms": {
"_index": [
"index-1",
"index-2"
]
}
},
{
"query_string": {
"query": "*man*"
}
}
]
}
}
}
How do you tell Elasticsearch that one full text field should be less relevant than other full text fields?
Suppose I have:
"query": {
"bool": {
"must": {
"query_string": {
"fields": ["my_id", "title^2", "intro", "body1", "body2", "body3", "footer"],
"default_operator": "AND",
"query": "some search query"
}
}
}
}
I want footer to be treated as less relevant than the others. What is the best approach to that?
Thanks
A boost value between 0 and 1.0 decreases the relevance score. So for example:
{
"query": {
"bool": {
"must": {
"query_string": {
"fields": [
...
"footer^0.5"
],
...
}
}
}
}
}
should do the trick.
I have this query:
{
"query": {
"bool": {
"must": [
{
"match": {
"egyik": {
"query": "piros alma"
}
}
},
{
"match": {
"masik": {
"query": "piros alma"
}
}
}
]
}
}
}
It's not too beautiful, because the query parameter occured twice, therefore I tried to rewrite it with the multi_match syntax:
{
"query": {
"bool": {
"must": {
"multi_match": {
"query": "piros alma",
"fields": [
"egyik",
"masik"
]
}
}
}
}
}
But it returns more hits than the first. I tried operator, minimum_should_match modifiers, but not helps. How do I solve the same result with multi_match?
As far as I know, all types of multi-match queries return a hit when the provided query matches any of the listed fields (see Elastic docs). Therefore, the reason why you have more hists with multi_match is that you can't enforce the same boolean condition you have with your first query. That said, I don't see anything wrong with repeating the same query parameter twice. If you want to generalise it a bit, you might want to consider using Search Templates
By default operator OR is used, which means query term can be present in any field, if you want query term to be present in all the fields then you can explicitly define operator field with AND value.
{
"query": {
"bool": {
"must": {
"multi_match": {
"query": "piros alma",
"fields": [
"egyik",
"masik"
],
"operator":"and"
}
}
}
}
}
To know more you can go through this
Meanwhile I found the solution:
{
"query": {
"bool": {
"must": {
"multi_match": {
"query": "piros alma",
"fields": [
"egyik",
"masik"
],
"type": "cross_fields",
"operator": "and"
}
}
}
}
}
Need the type and operator together.
I use ES 7, I want to search over multi fields, but on this field (title) must be shown firstly if it matches exactly. For now I tried :
{
"query": {
"bool": {
"must": {
"bool": {
"should": [
{
"match_phrase": {
"titre": {
"query": "test",
"boost": "20"
}
}
},
{
"multi_match": {
"fields": ["titre", "description^4", "subtitle^3"],
"query": "test",
"type": "most_fields"
}
}
]
}
}
}
}
}
It works, but I would like to order the match_phrase before other results.
The idea is the user type the exact phrase of a title, this result will appear before other based on multi_match.
Is it possible ?
Is there any way to boost search results on same field depending on type?
My basic boosting is something like:
GET _search
{
"query": {
"simple_query_string": {
"query": "mangan",
"fields":["_all", "title^6"]
}
}
}
But for some other documents I want title to be less important, so I tried to prefix it with type:
GET _search
{
"query": {
"simple_query_string": {
"query": "mangan",
"fields":[
"_all",
"DocumentationPage.title^6",
"DocumentationPage.title^6"]
}
}
}
But then it does not boost at all. As a last resort I could use Funcsion/Script Score bu would like to avoid it.
For sake of example, assume that document contains just title field.
A simple way to achieve this is re-writing the query in the OP as a dis-max query.
Example for elasticsearch 5.x:
{
"query": {
"dis_max": {
"queries": [
{
"simple_query_string": {
"fields": [
"_all"
],
"query": "mangan"
}
},
{
"bool": {
"filter": {
"type": {
"value": "DocumentationPage"
}
},
"must": [
{
"simple_query_string": {
"fields": [
"title^6"
],
"query": "mangan"
}
}
]
}
}
]
}
}
}