0
votes

I have Indexed title_o as non indexed field. Query to get exact search is not returning results. I need find documents when the title_o matches this is test1. Please help.

Indexed following documents:
curl -XPUT 'http://localhost:9200/test/test10/1' -d '
{
    "doi":"1234",
    "title":"this is test1",
     "title_o":"this is test1"

}'



curl -XPUT 'http://localhost:9200/test/test10/3' -d '
{
    "doi":"1234",
    "title":"this is test3",
     "title_o":"this is test3"

}'

Search:
curl -XGET 'http://localhost:9200/test/test10/_search?pretty=true' -d '
{
    "query" : {
        "filtered" : {
            "filter" : {
                "term" : {
                    "title_o" : "this is test1"
                }
            }
        }
    }
}'
3
Can you post the mapping?Tom

3 Answers

1
votes

For exact/term matches use not analyzed fields,

Working code:

curl -XGET 'http://localhost:9200/test/test10/_search?pretty=true' -d '
{
    "query" : {
        "filtered" : {
            "filter" : {
                "term" : {
                    "title_o.keyword" : "this is test1"
                }
            }
        }
    }
}'
0
votes

If you have your title field mapped as "index":"no", this tells ElasticSearch to make this field unavailable for search. In your case, make sure you have your field mapped as "index":"not_analyzed" if you plan on using this field for exact string matching.

0
votes

The curl requested you posted in comment:

curl -XGET 'localhost:9200/test/test10/_search?pretty=true' -d ' { "query" : { "filtered" : { "filter" : { "term" : { "title.title_o" : "This is test6" } } } } }'

differs with the one posted in the question.

This should work:

curl -XGET 'http://localhost:9200/test/test10/_search?pretty=true' -d '
{
    "query" : {
        "filtered" : {
            "filter" : {
                "term" : {
                    "title_o" : "this is test1"
                }
            }
        }
    }
}'