# Highlight по всем индексам через client.msearch

**URL:** <https://discuss.elastic.co/t/highlight-client-msearch/72296>\
**Category:** Вопросы на русском языке\
**Created:** [January 20, 2017, 1:51pm UTC](https://discuss.elastic.co/t/highlight-client-msearch/72296 "2017-01-20T13:51:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![whispersofdew](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/whispersofdew/32/11067_2.png) [@whispersofdew](https://discuss.elastic.co/u/whispersofdew)\
**Post date:** [January 20, 2017, 1:51pm UTC](https://discuss.elastic.co/t/highlight-client-msearch/72296/1 "2017-01-20T13:51:42Z")

</div>

Доброго времени суток.  
Очередной вопрос по хайлайтам.

Я создал поля с одинаковыми параметрами и флагом "store": "yes"

`"someField1" : { "type" : "string", "analyzer" : "my_analyzer", "store": "yes" }`

Далее я хочу получить результаты сразу по двум индексам, и чтоб каждый результат содержал highlight.  
Делаю запрос

```
client.msearch({
    body: [
        { index: "dima", type: ["someField1","someField2"] },
        {
            query: {
                match: {
                    _all: "япония"
                }
            }
        },
        {
            highlight: {
                require_field_match: false,
                fields: {
                    "*": {}
                }
            }
        },

    { index: 'ivan', type: 'someField3' },
    {
        query: {
            match: {
                _all: "япония"
            }
        }
    },
    {
        highlight: {
            require_field_match: false,
            fields: {
                "*": {}
            }
        }
    }
]

```

})

Но получаю в итоге вместо хайлайта

`{"responses":[{"took":9,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.095891505,"hits":[{"_index":"dima","_type":"type1","_id":"5","_score":0.095891505,"_source":{"someField1":"Январский дефицит платежного баланса Японии превысил $5 млрд"}}]}},{"error":{"root_cause":[{"type":"search_parse_exception","reason":"failed to parse search source. unknown search element [index]","line":1,"col":2}],"type":"search_phase_execution_except`

Я наверное не так подставлю кусок запроса?

{  
highlight: {  
require\_field\_match: false,  
fields: {  
"\*": {}  
}  
}  
}

Как запрашивать хайлайт когда ищу сразу по нескольким индексам?

Спасибо)

---

<div class="post-metadata">

**Author:** ![whispersofdew](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/whispersofdew/32/11067_2.png) [@whispersofdew](https://discuss.elastic.co/u/whispersofdew)\
**Post date:** [January 20, 2017, 2:15pm UTC](https://discuss.elastic.co/t/highlight-client-msearch/72296/2 "2017-01-20T14:15:31Z")

</div>

Вот в таком виде ошибки нет, но и хайлайта тоже нет

```
client.msearch({
    body: [
        // match all query, on all indices and types
        { index: "dima", type: ["someField1","someField2"] },
        {
            query: {
                match: {
                    _all: "япония"
                }
            }
        },
        {
            highlight: {
                require_field_match: false,
                fields: {
                    _all: {}
                }
            }
        }

```

Возвращает

`{"responses":[{"took":1,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.095891505,"hits":[{"_index":"dima","_type":"someField1","_id":"5","_score":0.095891505,"_source":{"someField1":"Январский дефицит платежного баланса Японии превысил $5 млрд"}}]}}]}`

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [January 20, 2017, 2:17pm UTC](https://discuss.elastic.co/t/highlight-client-msearch/72296/3 "2017-01-20T14:17:58Z")

</div>

`highlight` должен быть внутри секции с `query`. То есть структура должна быть такая:

```auto
{ index: ..... }
{
  query: {...},
  highlight: {...}
}

```

---

<div class="post-metadata">

**Author:** ![whispersofdew](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/whispersofdew/32/11067_2.png) [@whispersofdew](https://discuss.elastic.co/u/whispersofdew)\
**Post date:** [January 20, 2017, 2:22pm UTC](https://discuss.elastic.co/t/highlight-client-msearch/72296/4 "2017-01-20T14:22:41Z")

</div>

Спасибо!

---

<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:** [February 17, 2017, 2:22pm UTC](https://discuss.elastic.co/t/highlight-client-msearch/72296/5 "2017-02-17T14:22:47Z")

</div>

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