Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble with spaces in query to elasticsearh

I'm experiencing trouble with requesting fileds making requests on field with spaces. Mapping looks like this:

"myIndexName": {
    "mappings": {
        "myType": {
            "properties": {
                "myPropertyWithSpaces": {
                    "type": "string",
                    "analyzer": "analyzer_keyword"
                }
            }
        }
    }
}

There "analyzer_keyword" is cutom analyzer with keyword tokenizer and lowercase filter. When I'm sending "_analyze" request with "analyzer_keyword" analyzer and query like "firstWord secondWord" I get only token "firstword secondword" - everything works as expected. But querystring request returns nothing if I don't change space character to "?" wildcard; interesting, that lowercasing still works and such behaviour doesn't change if I'm telling elasticsearch to use this "analyzer_keyword" explicitly.

"query": {
"query_string": {
    "query": "firstWord secondWord",
    "default_field": "myPropertyWithSpaces",
    "analyzer": "analyzer_keyword"
}
like image 1000
Victor Suzdalev Avatar asked May 29 '14 20:05

Victor Suzdalev


People also ask

How do I retrieve more than 10000 results events in Elasticsearch?

By default, you cannot use from and size to page through more than 10,000 hits. This limit is a safeguard set by the index. max_result_window index setting. If you need to page through more than 10,000 hits, use the search_after parameter instead.

Why is Elasticsearch not returning all results?

The reason might be that you haven't provided the size parameter in the query. This limits the result count to 10 by default. Out of all the results the top 10 might be from the two index even thought the match is present in third index as well.

Why is Elasticsearch so slow?

Slow queries are often caused byPoorly written or expensive search queries. Poorly configured Elasticsearch clusters or indices. Saturated CPU, Memory, Disk and network resources on the cluster.


1 Answers

Found solution in simple escaping space character as "\ ". Works correctly and prevents queryString processor from injecting any "AND OR" operators or whatever.

like image 71
Victor Suzdalev Avatar answered Oct 01 '22 22:10

Victor Suzdalev