Может быть, этот пример будет вам полезен:
Отображение
PUT /so54071449
{
"mappings": {
"doc": {
"properties": {
"url": {
"type": "text",
"term_vector": "with_positions_offsets",
"fields": {
"simple": {
"type": "text",
"analyzer": "simple",
"search_analyzer": "simple",
"term_vector": "with_positions_offsets"
}
}
}
}
}
}
}
Добавить документ
POST /so54071449/doc
{
"url": "example.com"
}
Поиск по example
GET /so54071449/_search
{
"query": {
"multi_match": {
"query": "example",
"fields": ["url", "url.simple"]
}
},
"highlight": {
"fields": {
"url": {
"matched_fields": [
"url",
"url.simple"
]
}
}
}
}
Результат по example
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.25811607,
"hits": [
{
"_index": "so54071449",
"_type": "doc",
"_id": "AWgoEwDT2HOwokHu0yvd",
"_score": 0.25811607,
"_source": {
"url": "example.com"
},
"highlight": {
"url": [
"<em>example</em>.com"
]
}
}
]
}
}
Поиск по example.com
GET /so54071449/_search
{
"query": {
"multi_match": {
"query": "example.com",
"fields": ["url", "url.simple"]
}
},
"highlight": {
"fields": {
"url": {
"matched_fields": [
"url",
"url.simple"
]
}
}
}
}
Результат по example.com
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.51623213,
"hits": [
{
"_index": "so54071449",
"_type": "doc",
"_id": "AWgoEwDT2HOwokHu0yvd",
"_score": 0.51623213,
"_source": {
"url": "example.com"
},
"highlight": {
"url": [
"<em>example.com</em>"
]
}
}
]
}
}
Я использовал мультипол matched_fields
для объединения выделения результатов из url
и url.simple
в одно поле.