4
votes

I face the problem about writing Elasticsearch query.
My query is like below

{
"query": {
    "query_string": {
        "default_field": "content",
        "query": "@lin1"
    }
},
"from": 0,
"size": 1000,
"sort": [
    {
        "time": "desc"
    }
]
}

And I am using query_string
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
But the @ character can not match.
It will come out this kind of result: lin1 or 「lin1」

enter image description here

So how should I write the Elasticsearch query to match @lin1?

1
What text are you trying to match against?Andrei Stefan
I am searching @lin1Meteor
This I understood. In which text are you searching '@lin1'?Andrei Stefan
@Andrei Stefan string. Field is contentMeteor
So, you have Chinese characters, as well. And '@' can be found inside words? What are the words separated by? Please, post the mapping.Andrei Stefan

1 Answers

1
votes

It all depends on the analyzer you are using. For all you know, you are using the standard analyzer which discards the '@' symbol from the index. In that case, you'll never be able to search for the '@' symbol. But if that is not the case and you do have '@' indexed, you can modify the query_string section of your query to below:

"query_string": {
    "default_field": "content",
    "query": "@lin1",
    "analyzer": "whitespace"
}