# Elasticsearch CURL Query

**URL:** <https://discuss.elastic.co/t/elasticsearch-curl-query/247537>\
**Category:** Elasticsearch\
**Created:** [September 4, 2020, 12:35pm UTC](https://discuss.elastic.co/t/elasticsearch-curl-query/247537 "2020-09-04T12:35:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cyril\_Guiet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cyril_guiet/32/48107_2.png) [@Cyril\_Guiet](https://discuss.elastic.co/u/Cyril_Guiet)\
**Post date:** [September 4, 2020, 12:35pm UTC](https://discuss.elastic.co/t/elasticsearch-curl-query/247537/1 "2020-09-04T12:35:25Z")

</div>

Hi all !

I'm trying to merge multiple search query in ES but the result had no enough informations to match searched objects with results.

How can I do that ?

Thanks 🙂

**query sample:**

```
curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "terms": {
      "labels": ["Rebic", "Toto"],
      "boost": 1.0
    }
  }
}

curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
    "_source": ["labels", "id"],
    "query" : {
        "bool": {
            "should": [
                {"match" : { "labels" : "Rebic" }},
                {"match" : { "labels" : "Toto" }}
            ]
        }
    }
}' 

```

**response sample:**

```
{
  "took" : 6,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 15,
      "relation" : "eq"
    },
    "max_score" : 24.525375,
    "hits" : [
      {
        "_index" : "enwiki_latest",
        "_type" : "_doc",
        "_id" : "r-1jU3QBzwBIdiQJJlKB",
        "_score" : 24.525375,
        "_source" : {
          "id" : "\"Q87486800\"",
          "labels" : "{\"en\": {\"language\": \"en\", \"value\": \"Jelena Rebic\"}, \"nl\": {\"language\": \"nl\", \"value\": \"Jelena Rebic\"}}"
        }
      },
      {
        "_index" : "enwiki_latest",
        "_type" : "_doc",
        "_id" : "ktgeU3QBzwBIdiQJ2ssN",
        "_score" : 17.667746,
        "_source" : {
          "id" : "\"Q2384109\"",
          "labels" : "{\"fr\": {\"language\": \"fr\", \"value\": \"La T\\u00eate \\u00e0 Toto\"}}"
        }
      }
    ]
  }
}
```

---

<div class="post-metadata">

**Author:** ![Emanuil](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emanuil/32/36783_2.png) [@Emanuil](https://discuss.elastic.co/u/Emanuil)\
**Post date:** [September 4, 2020, 12:41pm UTC](https://discuss.elastic.co/t/elasticsearch-curl-query/247537/2 "2020-09-04T12:41:23Z")

</div>

> [@Cyril\_Guiet](#):
>
> the result had no enough informations to match searched objects with results.

Can you describe in more detail what you're trying to do? What is this system and what's the query for?

The relationship between result and query is that the first result contains the word "Rebic" and the second result contains the word "Toto", both in the field "labels". The queries worked. What other information do you need Elasticsearch to return?

---

<div class="post-metadata">

**Author:** ![Cyril\_Guiet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cyril_guiet/32/48107_2.png) [@Cyril\_Guiet](https://discuss.elastic.co/u/Cyril_Guiet)\
**Post date:** [September 4, 2020, 12:55pm UTC](https://discuss.elastic.co/t/elasticsearch-curl-query/247537/3 "2020-09-04T12:55:22Z")

</div>

Hello @Emanuil , thanks for your help

from my previous answer i would like to generate a response like that or something similar 🙂 :

**desired response sample:**

```
{
  "took" : 6,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 15,
      "relation" : "eq"
    },
    "max_score" : 24.525375,
    "hits" : [
      {
        "_index" : "enwiki_latest",
        "_type" : "_doc",
        "_id" : "r-1jU3QBzwBIdiQJJlKB",
        "_score" : 24.525375,
        **"_labels" : Rebic**
        "_source" : {
          "id" : "\"Q87486800\"",
          "labels" : "{\"en\": {\"language\": \"en\", \"value\": \"Jelena Rebic\"}, \"nl\": {\"language\": \"nl\", \"value\": \"Jelena Rebic\"}}"
        }
      },
      {
        "_index" : "enwiki_latest",
        "_type" : "_doc",
        "_id" : "ktgeU3QBzwBIdiQJ2ssN",
        "_score" : 17.667746,
        **"_labels" : Toto**
        "_source" : {
          "id" : "\"Q2384109\"",
          "labels" : "{\"fr\": {\"language\": \"fr\", \"value\": \"La T\\u00eate \\u00e0 Toto\"}}"
        }
      }
    ]
  }
}
```

---

<div class="post-metadata">

**Author:** ![Emanuil](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emanuil/32/36783_2.png) [@Emanuil](https://discuss.elastic.co/u/Emanuil)\
**Post date:** [September 4, 2020, 10:47pm UTC](https://discuss.elastic.co/t/elasticsearch-curl-query/247537/4 "2020-09-04T22:47:42Z")

</div>

I think you want the [highlight functionality](https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html). Maybe start with something simple to start, like the plain highlighter in [this example](https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html#set-highlighter-type).

EDIT: Let us know how it goes and share your query! It'll help other users (and is personally interesting..)

---

<div class="post-metadata">

**Author:** ![Cyril\_Guiet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cyril_guiet/32/48107_2.png) [@Cyril\_Guiet](https://discuss.elastic.co/u/Cyril_Guiet)\
**Post date:** [September 7, 2020, 3:30pm UTC](https://discuss.elastic.co/t/elasticsearch-curl-query/247537/5 "2020-09-07T15:30:12Z")

</div>

Hello !

in your case you will return the retrieve label , and I would like to remind wich match I searched 🙂

**query:**

```
 curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
    "_source": ["labels", "id"],
    "query" : {
        "bool": {
            "should": [
                {"match" : { "labels" : "Rebic" }},
                {"match" : { "labels" : "toto" }}
            ]
        }
    }
}' 

```

**desired response:**

{  
"took" : 9,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"skipped" : 0,  
"failed" : 0  
},  
"hits" : {  
"total" : {  
"value" : 7,  
"relation" : "eq"  
},  
"max\_score" : 20.856234,  
"hits" : [  
{  
"\_index" : "enwiki\_latest",  
"\_type" : "\_doc",  
"\_id" : "X38jaXQBb3qqttZ12sOf",  
"\_score" : 20.856234,  
**"\_from" : "Rebic",**  
"\_source" : {  
"id" : ""Q12897826""  
}  
},  
{  
"\_index" : "enwiki\_latest",  
"\_type" : "\_doc",  
"\_id" : "a4AkaXQBb3qqttZ1uSNW",  
"\_score" : 20.326504,  
**"\_from" : "Rebic",**  
"\_source" : {  
"id" : ""Q22322231""  
}  
},  
{  
"\_index" : "enwiki\_latest",  
"\_type" : "\_doc",  
"\_id" : "MYItaXQBb3qqttZ1hybj",  
"\_score" : 15.031863,  
**"\_from" : "Rebic",**  
"\_source" : {  
"id" : ""Q68961742""  
}  
},  
{  
"\_index" : "enwiki\_latest",  
"\_type" : "\_doc",  
"\_id" : "yH8iaXQBb3qqttZ1-muk",  
"\_score" : 14.735747,  
**"\_from" : "toto",**  
"\_source" : {  
"id" : ""Q4118198""  
}  
},  
{  
"\_index" : "enwiki\_latest",  
"\_type" : "\_doc",  
"\_id" : "YX8iaXQBb3qqttZ1Z0DN",  
"\_score" : 2.8115559,  
**"\_from" : "toto",**  
"\_source" : {  
"id" : ""Q192891""  
}  
}  
]  
}  
}

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 7, 2020, 3:45pm UTC](https://discuss.elastic.co/t/elasticsearch-curl-query/247537/6 "2020-09-07T15:45:54Z")

</div>

Have a look at [https://www.elastic.co/guide/en/elasticsearch/reference/7.9/query-dsl-bool-query.html#named-queries](https://www.elastic.co/guide/en/elasticsearch/reference/7.9/query-dsl-bool-query.html#named-queries)

---

<div class="post-metadata">

**Author:** ![Cyril\_Guiet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cyril_guiet/32/48107_2.png) [@Cyril\_Guiet](https://discuss.elastic.co/u/Cyril_Guiet)\
**Post date:** [September 8, 2020, 12:19pm UTC](https://discuss.elastic.co/t/elasticsearch-curl-query/247537/7 "2020-09-08T12:19:52Z")

</div>

perfect !

**QUERY**

```
curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
    "_source": ["labels", "id"],
    "query" : {
        "bool": {
            "should": [
		{ "match": { "labels": { "query": "titi", "_name": "titi_name" } } },
        	{ "match": { "labels": { "query": "toto", "_name": "toto_name" } } }
            ]
        }
    }
}' 

```

**RESPONSE**

```
  {
    "_index" : "enwiki_latest",
    "_type" : "_doc",
    "_id" : "xXwWaXQBb3qqttZ1ekxZ",
    "_score" : 21.006222,
    "_source" : {
      "id" : "\"Q31557634\"",
      "labels" : "{\"ceb\": {\"language\": \"ceb\", \"value\": \"Titi Swamp\"}, \"en\": {\"language\": \"en\", \"value\": \"Titi Swamp\"}}"
    },
    "matched_queries" : [
      "titi_name"
    ]
  },
  {
    "_index" : "enwiki_latest",
    "_type" : "_doc",
    "_id" : "a4AkaXQBb3qqttZ1uSNW",
    "_score" : 20.85733,
    "_source" : {
      "id" : "\"Q22322231\"",
      "labels" : "{\"fr\": {\"language\": \"fr\", \"value\": \"Toto\"}, \"en\": {\"language\": \"en\", \"value\": \"Toto\"}, \"es\": {\"language\": \"es\", \"value\": \"Toto\"}}"
    },
    "matched_queries" : [
      "toto_name"
    ]
  },
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 6, 2020, 12:20pm UTC](https://discuss.elastic.co/t/elasticsearch-curl-query/247537/8 "2020-10-06T12:20:00Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
