creating an index for percolate query

2019-09-16 19:36发布

问题:

I'm trying percolate query in elasticsearch, but creating an index as explained in the docs I'm greeted with an error. I ran the following:

PUT /my_percolate_index
{
  "mappings": {
    "doctype": {
        "properties": {
            "message": {
                "type": "text"
            }
        }
    },
    "queries": {
        "properties": {
            "query": {
                "type": "percolator"
            }
        }
    }
  }
}

I'm greeted with the following error:

{
  "error": {
    "root_cause": [
     {
       "type": "illegal_argument_exception",
       "reason": "Rejecting mapping update to [my_percolate_index] as the final mapping would have more than 1 type: [doctype, queries]"
     }
   ],
   "type": "illegal_argument_exception",
   "reason": "Rejecting mapping update to [my_percolate_index] as the final mapping would have more than 1 type: [doctype, queries]"
  },
  "status": 400
}

Am I missing something here?

回答1:

Since you're using ES 6, you just need to move the query field inside your mapping type

PUT /my_percolate_index
{
    "mappings": {
        "doctype": {
            "properties": {
                "message": {
                    "type": "text"
                },
                "query": {
                    "type": "percolator"
                }
            }
        }
    }
}

Note that as of ES 6, only a single mapping type is allowed within any index.