This notes will store some unstructured tips when I study Elasticsearch.
Exactly search in array
Generate docs and search “Tony Ma” in the tags:
PUT twitter/blog/1
{ "Company" : "Tencent",
"tg" : ["Tony Ma", "Tencent"]
}
PUT twitter/blog/2
{ "Company" : "Alibaba",
"tg": ["Tony", "Ma"]
}
GET twitter/blog/_search?q=tg:"Tony Ma"
Returns:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.5063205,
"hits": [
{
"_index": "twitter",
"_type": "blog",
"_id": "1",
"_score": 0.5063205,
"_source": {
"Company": "Tencent",
"tg": [
"Tony Ma",
"Tencent"
]
}
}
]
}
}
Remarks:
- The field names should be different in different types.