Elastic search parse a string

Hi,

I search a way to find a string inside another string by parsing it.

For example i index into elasticSearch a document that contain the text : "2000Newyork" in a field name "id"

And now i want to find the indexed document with a query like "2000" or "Newyork".

How can i do that ?

I would recommend you have a look at the wildcard field type as I believe it is the most efficient way to search for substrings.

I tried to do this :

                    var mq = QueryBuilders.wildcard().field("id")
                                    .wildcard(s)
                                    .build();

                    SearchRequest request = new SearchRequest.Builder()
                                    .index("home2")
                                    .size(size)
                                    .query(mq._toQuery())
                                    .build();

                    SearchResponse<Page> search = client.search(
                                    request,
                                    Page.class);

but it doesn't works.

You will need to make sure you have the appropriate mappings in your index. Also please do not post images of text as they are hard to read and search.

How can i update the mapping of a field with java api ?
I already tried with the documentation but it didn't help me.

You can generally not update mappings in Elasticsearch. Instead create an index template and reindex your data. I usually do this through Kibana, so can not help with the Java API.

I think that the default analyzer and the default behavior of the match query will work in that case.

Do you know how can i apply the standard analyzer to my query ?

It is applied through the mappings of the index, e.g. through an index template when the index is created. It is not controlled through the query.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.