0

I need to make a query in elasticsearch, such that, in the following text: "I want to go on holiday to New York with my family" find: "New York" in the field of a nested. I in my data I have a field that contains the word "New York" which is the type Nested and not_analyzed. Anyone know how to do this?

The query and I got it, and nobody help me.

2 Answers 2

4

Use a phrase query. From the docs:

{ "match_phrase" : { "message" : "this is a test" } } 

I do think that having "not_analyzed" is going to be a problem for you, as you actually want an analyzed field. You can specify the type of analyzer to use, which may work. But I would recommend using an analyzed field, if possible.

If you are willing to pay the space cost, I would recommend using a multi field with analyzed and not_analyzed parts. here is an example:

 "sender": { "type" : "multi_field", "fields" : { "sender" : {"type" : "string", "index" : "analyzed"}, "sender_not_analyzed" : {"type" : "string", "index" : "not_analyzed"} } } 
Sign up to request clarification or add additional context in comments.

2 Comments

I have to use it well, because I need to be not_analyzed, because that field is another query filter. Changing the type, as do the query?
More on this exact same use case here: elasticsearch.org/guide/en/elasticsearch/guide/current/…
0

not_analyzed means what it says, it isn't analyzed. It will be indexed as the literal string passed in, in a single token. If you make it analyzed, it will be tokenized and filtered in such a way as to make it useful for full-text searching. So do that.

Please see the documentation of ElasticSearch Analysis.

5 Comments

You change not_analyzed to analyzed.
Probably a phrasequery would be ideal, but I recommend you read up on some basic match queries as well.
Surprisingly rude, toward a couple people trying to help you, not sure what prompted that. Seriously though, not_analyzed is not correct, and should be changed, for this type of search. I imagine you have switched to a WildcardQuery, or something along those lines if you kept with a not_analyzed field, which means it will perform a linear search through the entire index, and performance on large data sets will drop through the floor.
I and @Paul_Sanwald both answered the question as well as possible given the information provided. If you ended up using a different approach, you should provide an answer indicating as much, instead.
Not what you asked, if you do not understand, and I have no way to explain to you. Stop giving negative points when it's you who does not answer what is asked.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.