3
votes

I have indexed documents with each over 100 field each analysed using Edge gram tokenizer to support Auto-Suggestion. I do require free text search that searches on all fields. When i am trying to do so, search is also happening fields with auto complete analyzed(ex. Data.autocomplete_analyzed). I have to restrict this by searching only fields analysed with type "text"(ex. Data). Is there a method to do so in 1. Index time 2. Query time. Mapping file:

    "mappings": {
                "_doc": {
                    "properties": {
                        "Data": {
                            "type": "text",
                            "fields": {
                                "autocomplete_analyzed": {
                                    "type": "text",
                                    "analyzer": "autocomplete"
                                },
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        }
                } 
               }

Search query :

 {
"query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "query": "aim",
            "type": "phrase",
            "slop": "2",
            "fields": []
          }
        },
        {
          "multi_match": {
            "query": "aim",
            "fuzziness": "1",
            "fields": []
          }
        }
      ],
      "minimum_should_match": 1 
}
1

1 Answers

0
votes

In query time you can use Source filtering to choose the fields you want.

    GET /_search
{
    "_source": [ "obj1.*", "obj2.*" ],
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}

If you use query_string for search you can use fields

    GET /_search
{
  "query": {
    "query_string": {
      "query": "this AND that OR thus",
      "fields": [
          "docfilename",
          "filepath",
          "singlewordfield"
        ]
    }
  }
}