My documents are like this.
{
"sourceTitle": "Arrival",
"otherFields": ...
}
{
"sourceTitle": "Arrival",
"otherFields": ...
}
{
"sourceTitle": "Eye in the Sky",
"otherFields": ...
}
I need two types queries on the field sourceTitle.
First, I need get all distinct values of sourceTitle, like this
Arrival
Eye in the Sky
Second, I need to support search. For example, if the user input "eye", i need find all the documents which sourceTitle contains "eye".
For the first query, I am using the term aggregation.
{
"size": 0,
"aggs": {
"sourceTitle": {
"terms": {
"field": "sourceTitle",
"size": 10
}
}
}
}
Because the source title may contain space, to avoid tokenizing, I have to make sourceTilte type to be "keyword". Then the query for searching "eye" does not return anything to me. How can I support both queries.
{
"query": {
"match": {
"sourceTitle": "Eye"
}
}
}