Search by complete text on array property

Hi,

I have following records:

curl -XPUT "http://localhost:9200/movies/movie/1" -d'
{
"title": "The Godfather",
"director": "Francis Ford Coppola",
"year": 1972,
"genres": ["Crime", "Drama"]
}'

curl -XPUT "http://localhost:9200/movies/movie/2" -d'
{
"title": "Lawrence of Arabia",
"director": "David Lean",
"year": 1962,
"genres": ["Adventure", "Biography", "Drama"]
}'

curl -XPUT "http://localhost:9200/movies/movie/3" -d'
{
"title": "To Kill a Mockingbird",
"director": "Robert Mulligan",
"year": 1962,
"genres": ["Crime", "Drama", "Mystery"]
}'

curl -XPUT "http://localhost:9200/movies/movie/4" -d'
{
"title": "To Kill a Mockingbird11",
"director": "Robert Mulligan",
"year": 1962,
"genres": ["Crime", "Drama values", "Mystery"]
}'

curl -XPUT "http://localhost:9200/movies/movie/5" -d'
{
"title": "Apocalypse Now",
"director": "Francis Ford Coppola",
"year": 1979,
"genres": ["Drama values test", "War"]
}'

curl -XPUT "http://localhost:9200/movies/movie/6" -d'
{
"title": "Kill Bill: Vol. 1",
"director": "Quentin Tarantino",
"year": 2003,
"genres": ["Action", "Crime", "Thriller", "Drama", "Drama values", "Drama values test"]
}'

curl -XPUT "http://localhost:9200/movies/movie/7" -d'
{
"title": "The Assassination of Jesse James by the Coward Robert Ford",
"director": "Andrew Dominik",
"year": 2007,
"genres": ["Biography", "Crime", "Drama", "Drama values"]
}'

If I search by "drama values", below are the expected results:

{
"title": "To Kill a Mockingbird11",
"director": "Robert Mulligan",
"year": 1962,
"genres": ["Crime", "Drama values", "Mystery"]
}

{
"title": "Kill Bill: Vol. 1",
"director": "Quentin Tarantino",
"year": 2003,
"genres": ["Action", "Crime", "Thriller", "Drama", "Drama values", "Drama values test"]
}

{
"title": "The Assassination of Jesse James by the Coward Robert Ford",
"director": "Andrew Dominik",
"year": 2007,
"genres": ["Biography", "Crime", "Drama", "Drama values"]
}

If I search by "drama values test", below are the expected results:

{
"title": "Kill Bill: Vol. 1",
"director": "Quentin Tarantino",
"year": 2003,
"genres": ["Action", "Crime", "Thriller", "Drama", "Drama values", "Drama values test"]
}

{
"title": "Apocalypse Now",
"director": "Francis Ford Coppola",
"year": 1979,
"genres": ["Drama values test", "War"]
}

If I search by "drama", it will display all results except following results:

{
"title": "To Kill a Mockingbird11",
"director": "Robert Mulligan",
"year": 1962,
"genres": ["Crime", "Drama values", "Mystery"]
}'

{
"title": "Apocalypse Now",
"director": "Francis Ford Coppola",
"year": 1979,
"genres": ["Drama values test", "War"]
}

I am new to elasticsearch. I tried many ways, but I did not get expected results.

Can you help me to achive this ?

What does your query look like, and what part isn't working as expected?

Search is dependent on the analyzer set . If you need exact match, you would need to store them as not_analyzed fields. Below is the example which might help you

My Mappings:

{
    "movies": {
        "mappings": {
            "movie": {
                "properties": {
                    "director": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "genres": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "title": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "year": {
                        "type": "long"
                    }
                }
            }
        }
    }
}

**Sample Query**

{
"query" : {"match" :{ "genres.keyword" : "Drama values" } }
}

{
"query" : {"match" :{ "genres.keyword" : "Drama values test" } }
}

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